Skip to content

Commit

Permalink
Remove USE_ES6_IMPORT_META setting
Browse files Browse the repository at this point in the history
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 #9234 and #8729
  • Loading branch information
sbc100 committed Dec 17, 2024
1 parent 3ffc9a0 commit 4e72877
Show file tree
Hide file tree
Showing 12 changed files with 16 additions and 51 deletions.
4 changes: 4 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ See docs/process.md for more on how version tagging works.

3.1.75 (in development)
-----------------------
- The `USE_ES6_IMPORT_META` settings was removed. This setting was always
on by default, but now it cannot be disabled. This setting was originally
added in 2019 as a temporary measuse while engines and bundlers learned to
deal with `import meta`. (#23171)

3.1.74 - 12/14/24
-----------------
Expand Down
12 changes: 0 additions & 12 deletions site/source/docs/tools_reference/settings_reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1977,18 +1977,6 @@ This is implicitly enabled if the output suffix is set to 'mjs'.

Default value: false

.. _use_es6_import_meta:

USE_ES6_IMPORT_META
===================

Use the ES6 Module relative import feature 'import.meta.url'
to auto-detect WASM Module path.
It might not be supported on old browsers / toolchains. This setting
may not be disabled when Node.js is targeted (-sENVIRONMENT=*node*).

Default value: true

.. _export_name:

EXPORT_NAME
Expand Down
6 changes: 3 additions & 3 deletions src/library_pthread.js
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ var LibraryPThread = {
#endif
#endif
};
#if EXPORT_ES6 && USE_ES6_IMPORT_META
#if EXPORT_ES6
// If we're using module output, use bundler-friendly pattern.
#if PTHREADS_DEBUG
dbg(`Allocating a new web worker from ${import.meta.url}`);
Expand All @@ -434,7 +434,7 @@ var LibraryPThread = {
// the first case in their bundling step. The latter ends up producing an invalid
// URL to import from the server (e.g., for webpack the file:// path).
worker = new Worker(new URL('{{{ TARGET_JS_NAME }}}', import.meta.url), workerOptions);
#else
#else // EXPORT_ES6
var pthreadMainJs = _scriptName;
#if expectToReceiveOnModule('mainScriptUrlOrBlob')
// We can't use makeModuleReceiveWithVar here since we want to also
Expand All @@ -457,7 +457,7 @@ var LibraryPThread = {
} else
#endif
worker = new Worker(pthreadMainJs, workerOptions);
#endif // EXPORT_ES6 && USE_ES6_IMPORT_META
#endif // EXPORT_ES6
PThread.unusedWorkers.push(worker);
},

Expand Down
2 changes: 1 addition & 1 deletion src/parseTools.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export function processMacros(text, filename) {
// Also handles #include x.js (similar to C #include <file>)
export function preprocess(filename) {
let text = read(filename);
if (EXPORT_ES6 && USE_ES6_IMPORT_META) {
if (EXPORT_ES6) {
// `eval`, Terser and Closure don't support module syntax; to allow it,
// we need to temporarily replace `import.meta` and `await import` usages
// with placeholders during preprocess phase, and back after all the other ops.
Expand Down
4 changes: 2 additions & 2 deletions src/preamble.js
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ var wasmBinaryFile = '{{{ WASM_BINARY_FILE }}}';
#else
var wasmBinaryFile;
function findWasmBinary() {
#if EXPORT_ES6 && USE_ES6_IMPORT_META && !AUDIO_WORKLET
#if EXPORT_ES6 && !AUDIO_WORKLET
if (Module['locateFile']) {
#endif
var f = '{{{ WASM_BINARY_FILE }}}';
Expand All @@ -619,7 +619,7 @@ function findWasmBinary() {
}
#endif
return f;
#if EXPORT_ES6 && USE_ES6_IMPORT_META && !AUDIO_WORKLET // In single-file mode, repeating WASM_BINARY_FILE would emit the contents again. For an Audio Worklet, we cannot use `new URL()`.
#if EXPORT_ES6 && !AUDIO_WORKLET // In single-file mode, repeating WASM_BINARY_FILE would emit the contents again. For an Audio Worklet, we cannot use `new URL()`.
}
#if ENVIRONMENT_MAY_BE_SHELL
if (ENVIRONMENT_IS_SHELL)
Expand Down
8 changes: 1 addition & 7 deletions src/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -1353,13 +1353,6 @@ var MODULARIZE = false;
// [link]
var EXPORT_ES6 = false;

// Use the ES6 Module relative import feature 'import.meta.url'
// to auto-detect WASM Module path.
// It might not be supported on old browsers / toolchains. This setting
// may not be disabled when Node.js is targeted (-sENVIRONMENT=*node*).
// [link]
var USE_ES6_IMPORT_META = true;

// Global variable to export the module as for environments without a
// standardized module loading system (e.g. the browser and SM shell).
// [link]
Expand Down Expand Up @@ -2267,4 +2260,5 @@ var LEGACY_SETTINGS = [
['MIN_IE_VERSION', [0x7FFFFFFF], 'No longer supported'],
['WORKAROUND_OLD_WEBGL_UNIFORM_UPLOAD_IGNORED_OFFSET_BUG', [0], 'No longer supported'],
['AUTO_ARCHIVE_INDEXES', [0, 1], 'No longer needed'],
['USE_ES6_IMPORT_META', [1], 'Disabling is no longer supported'],
];
2 changes: 1 addition & 1 deletion test/other/test_unoptimized_code_size.js.size
Original file line number Diff line number Diff line change
@@ -1 +1 @@
53980
53979
2 changes: 1 addition & 1 deletion test/other/test_unoptimized_code_size_no_asserts.js.size
Original file line number Diff line number Diff line change
@@ -1 +1 @@
29400
29399
2 changes: 1 addition & 1 deletion test/other/test_unoptimized_code_size_strict.js.size
Original file line number Diff line number Diff line change
@@ -1 +1 @@
52776
52775
15 changes: 0 additions & 15 deletions test/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,16 +403,6 @@ def test_emcc_output_mjs_closure(self):
self.assertContained('new URL("hello_world.wasm", import.meta.url)', src)
self.assertContained('hello, world!', self.run_js('hello_world.mjs'))

def test_emcc_output_mjs_web_no_import_meta(self):
# Ensure we don't emit import.meta.url at all for:
# ENVIRONMENT=web + EXPORT_ES6 + USE_ES6_IMPORT_META=0
self.run_process([EMCC, '-o', 'hello_world.mjs',
test_file('hello_world.c'),
'-sENVIRONMENT=web', '-sUSE_ES6_IMPORT_META=0'])
src = read_file('hello_world.mjs')
self.assertNotContained('import.meta.url', src)
self.assertContained('export default Module;', src)

def test_export_es6_implies_modularize(self):
self.run_process([EMCC, test_file('hello_world.c'), '-sEXPORT_ES6'])
src = read_file('a.out.js')
Expand All @@ -422,11 +412,6 @@ def test_export_es6_requires_modularize(self):
err = self.expect_fail([EMCC, test_file('hello_world.c'), '-sEXPORT_ES6', '-sMODULARIZE=0'])
self.assertContained('EXPORT_ES6 requires MODULARIZE to be set', err)

def test_export_es6_node_requires_import_meta(self):
err = self.expect_fail([EMCC, test_file('hello_world.c'),
'-sENVIRONMENT=node', '-sEXPORT_ES6', '-sUSE_ES6_IMPORT_META=0'])
self.assertContained('EXPORT_ES6 and ENVIRONMENT=*node* requires USE_ES6_IMPORT_META to be set', err)

def test_export_es6_allows_export_in_post_js(self):
self.run_process([EMCC, test_file('hello_world.c'), '-O3', '-sEXPORT_ES6', '--post-js', test_file('export_module.js')])
src = read_file('a.out.js')
Expand Down
9 changes: 2 additions & 7 deletions tools/link.py
Original file line number Diff line number Diff line change
Expand Up @@ -1440,11 +1440,6 @@ def phase_linker_setup(options, state, newargs): # noqa: C901, PLR0912, PLR0915
if 'MODULARIZE' in user_settings:
exit_with_error('EXPORT_ES6 requires MODULARIZE to be set')
settings.MODULARIZE = 1
if settings.ENVIRONMENT_MAY_BE_NODE and not settings.USE_ES6_IMPORT_META:
# EXPORT_ES6 + ENVIRONMENT=*node* requires the use of import.meta.url
if 'USE_ES6_IMPORT_META' in user_settings:
exit_with_error('EXPORT_ES6 and ENVIRONMENT=*node* requires USE_ES6_IMPORT_META to be set')
settings.USE_ES6_IMPORT_META = 1

if settings.MODULARIZE and not settings.DECLARE_ASM_MODULE_EXPORTS:
# When MODULARIZE option is used, currently requires declaring all module exports
Expand Down Expand Up @@ -2074,7 +2069,7 @@ def phase_source_transforms(options):
# both main code and libraries.
# See also: `preprocess` in parseTools.js.
def fix_es6_import_statements(js_file):
if not settings.EXPORT_ES6 or not settings.USE_ES6_IMPORT_META:
if not settings.EXPORT_ES6:
return

src = read_file(js_file)
Expand Down Expand Up @@ -2426,7 +2421,7 @@ def modularize():
# In EXPORT_ES6 + PTHREADS the 'thread' is actually an ES6 module
# webworker running in strict mode, so doesn't have access to 'document'.
# In this case use 'import.meta' instead.
if settings.EXPORT_ES6 and settings.USE_ES6_IMPORT_META:
if settings.EXPORT_ES6:
script_url = 'import.meta.url'
else:
script_url = "typeof document != 'undefined' ? document.currentScript?.src : undefined"
Expand Down
1 change: 0 additions & 1 deletion tools/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@
'HEADLESS',
'MODULARIZE',
'EXPORT_ES6',
'USE_ES6_IMPORT_META',
'EXPORT_NAME',
'DYNAMIC_EXECUTION',
'PTHREAD_POOL_SIZE',
Expand Down

0 comments on commit 4e72877

Please sign in to comment.