Skip to content

Commit 4800608

Browse files
committed
Remove USE_ES6_IMPORT_META setting
This setting was added (IIUC) as a temporary workaround for the lack or support for `import.meta` in browser and tooling. However `import.meta` has been at stage 4 for almost 5 years now: tc39/proposal-import-meta#21 Webback (released in 2020) also has builtin support for `import.meta`, so I would hope the use case for disabling this setting no longer exists. See emscripten-core#9234 and emscripten-core#8729
1 parent 184834f commit 4800608

File tree

9 files changed

+18
-48
lines changed

9 files changed

+18
-48
lines changed

ChangeLog.md

+4
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,10 @@ See docs/process.md for more on how version tagging works.
140140
- The code geneated in `--proxy-to-worker` no longer contains support for
141141
reading the `?noProxy` URL parameter (this was not documented or tested).
142142
(#23297)
143+
- The `USE_ES6_IMPORT_META` settings was removed. This setting was always
144+
on by default, but now it cannot be disabled. This setting was originally
145+
added in 2019 as a temporary measure while engines and bundlers learned to
146+
deal with `import meta`. (#23171)
143147

144148
3.1.74 - 12/14/24
145149
-----------------

site/source/docs/tools_reference/settings_reference.rst

-12
Original file line numberDiff line numberDiff line change
@@ -1978,18 +1978,6 @@ This is implicitly enabled if the output suffix is set to 'mjs'.
19781978

19791979
Default value: false
19801980

1981-
.. _use_es6_import_meta:
1982-
1983-
USE_ES6_IMPORT_META
1984-
===================
1985-
1986-
Use the ES6 Module relative import feature 'import.meta.url'
1987-
to auto-detect WASM Module path.
1988-
It might not be supported on old browsers / toolchains. This setting
1989-
may not be disabled when Node.js is targeted (-sENVIRONMENT=*node*).
1990-
1991-
Default value: true
1992-
19931981
.. _export_name:
19941982

19951983
EXPORT_NAME

src/lib/libpthread.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ var LibraryPThread = {
418418
// Creates a new web Worker and places it in the unused worker pool to wait for its use.
419419
allocateUnusedWorker() {
420420
var worker;
421-
#if EXPORT_ES6 && USE_ES6_IMPORT_META
421+
#if EXPORT_ES6
422422
// If we're using module output, use bundler-friendly pattern.
423423
#if PTHREADS_DEBUG
424424
dbg(`Allocating a new web worker from ${import.meta.url}`);
@@ -440,7 +440,7 @@ var LibraryPThread = {
440440
// the first case in their bundling step. The latter ends up producing an invalid
441441
// URL to import from the server (e.g., for webpack the file:// path).
442442
worker = new Worker(new URL('{{{ TARGET_JS_NAME }}}', import.meta.url), {{{ pthreadWorkerOptions }}});
443-
#else
443+
#else // EXPORT_ES6
444444
var pthreadMainJs = _scriptName;
445445
#if expectToReceiveOnModule('mainScriptUrlOrBlob')
446446
// We can't use makeModuleReceiveWithVar here since we want to also
@@ -463,7 +463,7 @@ var LibraryPThread = {
463463
} else
464464
#endif
465465
worker = new Worker(pthreadMainJs, {{{ pthreadWorkerOptions }}});
466-
#endif // EXPORT_ES6 && USE_ES6_IMPORT_META
466+
#endif // EXPORT_ES6
467467
PThread.unusedWorkers.push(worker);
468468
},
469469

src/parseTools.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ function findIncludeFile(filename, currentDir) {
6565
// Also handles #include x.js (similar to C #include <file>)
6666
export function preprocess(filename) {
6767
let text = readFile(filename);
68-
if (EXPORT_ES6 && USE_ES6_IMPORT_META) {
68+
if (EXPORT_ES6) {
6969
// `eval`, Terser and Closure don't support module syntax; to allow it,
7070
// we need to temporarily replace `import.meta` and `await import` usages
7171
// with placeholders during preprocess phase, and back after all the other ops.

src/preamble.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -564,11 +564,11 @@ var wasmBinaryFile = '{{{ WASM_BINARY_FILE }}}';
564564
#else
565565
var wasmBinaryFile;
566566
function findWasmBinary() {
567-
#if EXPORT_ES6 && USE_ES6_IMPORT_META && !AUDIO_WORKLET
567+
#if EXPORT_ES6 && !AUDIO_WORKLET
568568
if (Module['locateFile']) {
569569
#endif
570570
return locateFile('{{{ WASM_BINARY_FILE }}}');
571-
#if EXPORT_ES6 && USE_ES6_IMPORT_META && !AUDIO_WORKLET // For an Audio Worklet, we cannot use `new URL()`.
571+
#if EXPORT_ES6 && !AUDIO_WORKLET // For an Audio Worklet, we cannot use `new URL()`.
572572
}
573573
#if ENVIRONMENT_MAY_BE_SHELL
574574
if (ENVIRONMENT_IS_SHELL) {

src/settings.js

+1-7
Original file line numberDiff line numberDiff line change
@@ -1353,13 +1353,6 @@ var MODULARIZE = false;
13531353
// [link]
13541354
var EXPORT_ES6 = false;
13551355

1356-
// Use the ES6 Module relative import feature 'import.meta.url'
1357-
// to auto-detect WASM Module path.
1358-
// It might not be supported on old browsers / toolchains. This setting
1359-
// may not be disabled when Node.js is targeted (-sENVIRONMENT=*node*).
1360-
// [link]
1361-
var USE_ES6_IMPORT_META = true;
1362-
13631356
// Global variable to export the module as for environments without a
13641357
// standardized module loading system (e.g. the browser and SM shell).
13651358
// [link]
@@ -2270,4 +2263,5 @@ var LEGACY_SETTINGS = [
22702263
['MIN_IE_VERSION', [0x7FFFFFFF], 'No longer supported'],
22712264
['WORKAROUND_OLD_WEBGL_UNIFORM_UPLOAD_IGNORED_OFFSET_BUG', [0], 'No longer supported'],
22722265
['AUTO_ARCHIVE_INDEXES', [0, 1], 'No longer needed'],
2266+
['USE_ES6_IMPORT_META', [1], 'Disabling is no longer supported'],
22732267
];

test/test_other.py

-15
Original file line numberDiff line numberDiff line change
@@ -402,16 +402,6 @@ def test_emcc_output_mjs_closure(self):
402402
self.assertContained('new URL("hello_world.wasm", import.meta.url)', src)
403403
self.assertContained('hello, world!', self.run_js('hello_world.mjs'))
404404

405-
def test_emcc_output_mjs_web_no_import_meta(self):
406-
# Ensure we don't emit import.meta.url at all for:
407-
# ENVIRONMENT=web + EXPORT_ES6 + USE_ES6_IMPORT_META=0
408-
self.run_process([EMCC, '-o', 'hello_world.mjs',
409-
test_file('hello_world.c'),
410-
'-sENVIRONMENT=web', '-sUSE_ES6_IMPORT_META=0'])
411-
src = read_file('hello_world.mjs')
412-
self.assertNotContained('import.meta.url', src)
413-
self.assertContained('export default Module;', src)
414-
415405
def test_export_es6_implies_modularize(self):
416406
self.run_process([EMCC, test_file('hello_world.c'), '-sEXPORT_ES6'])
417407
src = read_file('a.out.js')
@@ -421,11 +411,6 @@ def test_export_es6_requires_modularize(self):
421411
err = self.expect_fail([EMCC, test_file('hello_world.c'), '-sEXPORT_ES6', '-sMODULARIZE=0'])
422412
self.assertContained('EXPORT_ES6 requires MODULARIZE to be set', err)
423413

424-
def test_export_es6_node_requires_import_meta(self):
425-
err = self.expect_fail([EMCC, test_file('hello_world.c'),
426-
'-sENVIRONMENT=node', '-sEXPORT_ES6', '-sUSE_ES6_IMPORT_META=0'])
427-
self.assertContained('EXPORT_ES6 and ENVIRONMENT=*node* requires USE_ES6_IMPORT_META to be set', err)
428-
429414
@parameterized({
430415
'': ([],),
431416
# load a worker before startup to check ES6 modules there as well

tools/link.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -1432,11 +1432,11 @@ def phase_linker_setup(options, linker_args): # noqa: C901, PLR0912, PLR0915
14321432

14331433
set_initial_memory()
14341434

1435-
if settings.EXPORT_ES6 and settings.ENVIRONMENT_MAY_BE_NODE and not settings.USE_ES6_IMPORT_META:
1436-
# EXPORT_ES6 + ENVIRONMENT=*node* requires the use of import.meta.url
1437-
if 'USE_ES6_IMPORT_META' in user_settings:
1438-
exit_with_error('EXPORT_ES6 and ENVIRONMENT=*node* requires USE_ES6_IMPORT_META to be set')
1439-
settings.USE_ES6_IMPORT_META = 1
1435+
if settings.EXPORT_ES6 and not settings.MODULARIZE:
1436+
# EXPORT_ES6 requires output to be a module
1437+
if 'MODULARIZE' in user_settings:
1438+
exit_with_error('EXPORT_ES6 requires MODULARIZE to be set')
1439+
settings.MODULARIZE = 1
14401440

14411441
if settings.MODULARIZE and not settings.DECLARE_ASM_MODULE_EXPORTS:
14421442
# When MODULARIZE option is used, currently requires declaring all module exports
@@ -2065,7 +2065,7 @@ def phase_source_transforms(options):
20652065
# both main code and libraries.
20662066
# See also: `preprocess` in parseTools.js.
20672067
def fix_es6_import_statements(js_file):
2068-
if not settings.EXPORT_ES6 or not settings.USE_ES6_IMPORT_META:
2068+
if not settings.EXPORT_ES6:
20692069
return
20702070

20712071
src = read_file(js_file)
@@ -2415,7 +2415,7 @@ def modularize():
24152415
# In EXPORT_ES6 + PTHREADS the 'thread' is actually an ES6 module
24162416
# webworker running in strict mode, so doesn't have access to 'document'.
24172417
# In this case use 'import.meta' instead.
2418-
if settings.EXPORT_ES6 and settings.USE_ES6_IMPORT_META:
2418+
if settings.EXPORT_ES6:
24192419
script_url = 'import.meta.url'
24202420
else:
24212421
script_url = "typeof document != 'undefined' ? document.currentScript?.src : undefined"

tools/settings.py

-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@
6868
'HEADLESS',
6969
'MODULARIZE',
7070
'EXPORT_ES6',
71-
'USE_ES6_IMPORT_META',
7271
'EXPORT_NAME',
7372
'DYNAMIC_EXECUTION',
7473
'PTHREAD_POOL_SIZE',

0 commit comments

Comments
 (0)