Skip to content

Commit aa4705a

Browse files
authored
fix: test262 runner module rules override with { type: 'text' } (#20665)
1 parent a836e06 commit aa4705a

4 files changed

Lines changed: 17 additions & 7 deletions

File tree

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// This file contains invalid JavaScript on purpose.
2+
// When imported with { type: "text" }, it should be treated as a string, not parsed as JS.
3+
4+
invalid { javascript
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import value from "./fixture.js" with { type: "text" };
2+
3+
it("should import .js file as text string when using with { type: 'text' }", () => {
4+
expect(typeof value).toBe("string");
5+
expect(value).toContain("invalid { javascript");
6+
});
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
"use strict";
2+
3+
/** @type {import("../../../../").Configuration} */
4+
module.exports = {};

test/test262.spectest.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -497,9 +497,9 @@ const compile = async (entry, scenario, options = {}) =>
497497
scenario === "module"
498498
? [
499499
{
500-
// Avoid override `type` when we have `bytes` type, maybe we can improve this too
500+
// Avoid override `type` when we have `bytes` or `text` type
501501
with: {
502-
type: (value) => value !== "bytes"
502+
type: (value) => value !== "bytes" && value !== "text"
503503
},
504504
test: /\.js$/,
505505
type: "javascript/esm"
@@ -819,11 +819,7 @@ const knownBugs = [
819819
"expressions/dynamic-import/custom-primitive.js",
820820
// `import.meta` in script context should throw SyntaxError
821821
"expressions/import.meta/syntax/goal-script.js",
822-
// `with { type: 'text' }` import-text tests: test262 runner rule forces .js to javascript/esm, overriding asset/source
823-
"import/import-attributes/text-empty.js",
824-
"import/import-attributes/text-javascript.js",
825-
"import/import-attributes/text-self.js",
826-
"import/import-attributes/text-string.js",
822+
// `with { type: 'text' }`: asset/source modules use module.exports, preventing pure ESM output for vm.SourceTextModule
827823
"import/import-attributes/text-via-namespace.js",
828824
// Bundler limitation: all modules share a single bundle-level import.meta, so distinct-per-module cannot be satisfied
829825
"expressions/import.meta/distinct-for-each-module.js",

0 commit comments

Comments
 (0)