google / google/closure-compiler

Cannot compile import.meta

Open
#3,834 1 comment 1 reaction 1 assignee Claimed by @ChadKillingsworth View on GitHub
triage-done
Dominant language
JavaScript
Stars
7.7k
Forks
1.2k
Avg merge
2d 12h
Merged PRs (30d)
6

Description

[This comment](https://github.com/google/closure-compiler/issues/3707#issuecomment-834744655) 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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.