pigpigyyy / Yuescript

A Moonscript dialect compiles to Lua.
http://yuescript.org
MIT License
461 stars 39 forks source link

Remove restriction from import ... from "string" #159

Closed dankmolot closed 12 months ago

dankmolot commented 12 months ago

Currently import statement checks string by pattern that requires A-Za-z0-9\-_ at the start, and only then allows . after first character is allowed symbol. But this pattern check removes flexibility of using custom require.

In Garry's Mod I'm making npm-like package manager that also allows to use require like ESM import statement. For example ./module.lua, package-b and https://example.com/module.lua. But current implementation of parser disallows use of first and last example, since first starts with ., and second has :.

Is it necessary to have this limitation?

pigpigyyy commented 12 months ago

The restriction from import statement is for adding possible static checking functions with standardized module path in the future. And you can currently use the require function call for the general dynamic module loading purpose.

import a, b, c from require "https://example.com/module.lua"
dankmolot commented 12 months ago

Alright, many thanks for such a fast response and workaround for this problem!