Skip to content

Commit 9a165b7

Browse files
test(test262): parse the strict scenario strictly, not just run it
The scenario put the directive on the bundled output, so a test ran strictly but was still parsed as sloppy source. A loader now puts it on the entry instead, which is what test262 means by the strict variant. That alone un-skips the `yield` case: webpack already rejects the reserved word once it parses the test strictly.
1 parent 063b3b2 commit 9a165b7

2 files changed

Lines changed: 30 additions & 6 deletions

File tree

‎test/helpers/prependUseStrict.js‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
MIT License http://www.opensource.org/licenses/mit-license.php
3+
Author Alexander Akait @alexander-akait
4+
*/
5+
6+
"use strict";
7+
8+
/**
9+
* test262's strict scenario runs the test source with the directive prepended,
10+
* so webpack has to parse it strictly rather than only run it strictly.
11+
* @param {string} source the module source
12+
* @returns {string} the source parsed under strict mode
13+
*/
14+
module.exports = function prependUseStrict(source) {
15+
return `"use strict";\n${source}`;
16+
};

‎test/test262.spectest.js‎

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -620,9 +620,19 @@ const compile = async (entry, scenario, options = {}) =>
620620
reexportExportsPresence: exportsPresence || false
621621
}
622622
},
623-
rules:
623+
rules: [
624+
// The strict scenario is defined as the source carrying the
625+
// directive, so the entry is parsed strictly, not only run so.
626+
...(scenario === "strict"
627+
? [
628+
{
629+
test: (resource) => resource === entry,
630+
use: path.resolve(__dirname, "./helpers/prependUseStrict.js")
631+
}
632+
]
633+
: []),
624634
// For top level await, maybe we can improve our parser to detect and switch to module
625-
scenario === "module"
635+
...(scenario === "module"
626636
? [
627637
{
628638
// Avoid override `type` when we have `bytes` or `text` type
@@ -645,7 +655,8 @@ const compile = async (entry, scenario, options = {}) =>
645655
system: false
646656
}
647657
}
648-
]
658+
])
659+
]
649660
},
650661
externals: [
651662
({ context, request }, callback) => {
@@ -889,9 +900,6 @@ const knownBugs = [
889900
// `getOwnPropertyNames` sees webpack's `__esModule` next to `default`, so the
890901
// namespace has two own keys where the spec has one.
891902
"import/import-attributes/json-via-namespace.js",
892-
// The "strict" scenario prepends the directive to the bundled output, not to
893-
// the source, so webpack parses `yield` as a plain identifier.
894-
"expressions/dynamic-import/import-attributes/2nd-param-yield-ident-invalid.js",
895903
// Improvement- bug with `delete` and `ns[0] = something` when using `import * as ns from "...";`
896904
"module-code/export-expname-binding-index.js",
897905
// `String(ns)`/`Number(ns)` rely on `ns`'s prototype being `null` (a real

0 commit comments

Comments
 (0)