closure-compiler icon indicating copy to clipboard operation
closure-compiler copied to clipboard

Cannot compile import.meta

Open AshleyScirra opened this issue 3 years ago • 1 comments

This comment appears to indicate pass-through for import.meta is supported, but it still doesn't seem to work in v20210601.

Input test.js: console.log(import.meta.url);

Command line: java -jar ./closure-compiler.jar --compilation_level SIMPLE --language_in ECMASCRIPT_2020 --language_out ECMASCRIPT_2020 --allow_dynamic_import --js test.js --js_output_file out.js

Output:

test.js:1:12: ERROR - [JSC_CANNOT_CONVERT] This code cannot be converted from ES6. import.meta
  1| console.log(import.meta.url);
                 ^^^^^^^^^^^

1 error(s), 0 warning(s)

We previously used document.currentScript.src, which Closure accepts fine (and our code knows about how Closure can transform and combine files, and handles it accordingly). However the lack of Closure support for import.meta blocks us switching from classic scripts to modules. It should have the same kind of pass-through support as was added for dynamic import.

AshleyScirra avatar Jun 16 '21 15:06 AshleyScirra

I can repro this with v20210601.

@ChadKillingsworth , looks like import.meta is not supported in code here - https://github.com/google/closure-compiler/blob/bba5661a295b607d0f935cb06a00f2ea6eb3824a/src/com/google/javascript/jscomp/Es6RewriteModules.java#L401 ?

rishipal avatar Jun 18 '21 01:06 rishipal