ses 1.15.0 → 1.15.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lockdown.cjs +93 -8
- package/dist/lockdown.mjs +93 -8
- package/dist/lockdown.umd.js +93 -8
- package/dist/lockdown.umd.min.js +1 -1
- package/dist/ses-hermes.cjs +93 -8
- package/dist/ses.cjs +93 -8
- package/dist/ses.mjs +93 -8
- package/dist/ses.umd.js +93 -8
- package/dist/ses.umd.min.js +1 -1
- package/package.json +2 -2
- package/src/transforms.js +91 -6
package/dist/lockdown.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// ses@1.15.
|
|
1
|
+
// ses@1.15.1
|
|
2
2
|
(functors => options => {
|
|
3
3
|
'use strict';
|
|
4
4
|
|
|
@@ -8043,7 +8043,8 @@ const sourceMetaEntriesRegExp = new FERAL_REG_EXP(
|
|
|
8043
8043
|
})()
|
|
8044
8044
|
,
|
|
8045
8045
|
// === 33. ses ./src/transforms.js ===
|
|
8046
|
-
({imports:$h͏_imports,liveVar:$h͏_live,onceVar:$h͏_once,import:$h͏_import,importMeta:$h͏____meta})=>(function(){'use strict';let FERAL_REG_EXP,SyntaxError,regexpReplace,sealRegexp,stringSearch,stringSlice,stringSplit,freeze,getSourceURL;$h͏_imports([["./commons.js", [["FERAL_REG_EXP",[$h͏_a => (FERAL_REG_EXP = $h͏_a)]],["SyntaxError",[$h͏_a => (SyntaxError = $h͏_a)]],["regexpReplace",[$h͏_a => (regexpReplace = $h͏_a)]],["sealRegexp",[$h͏_a => (sealRegexp = $h͏_a)]],["stringSearch",[$h͏_a => (stringSearch = $h͏_a)]],["stringSlice",[$h͏_a => (stringSlice = $h͏_a)]],["stringSplit",[$h͏_a => (stringSplit = $h͏_a)]],["freeze",[$h͏_a => (freeze = $h͏_a)]]]],["./get-source-url.js", [["getSourceURL",[$h͏_a => (getSourceURL = $h͏_a)]]]]]);
|
|
8046
|
+
({imports:$h͏_imports,liveVar:$h͏_live,onceVar:$h͏_once,import:$h͏_import,importMeta:$h͏____meta})=>(function(){'use strict';let FERAL_REG_EXP,SyntaxError,regexpExec,regexpReplace,sealRegexp,stringSearch,stringSlice,stringSplit,freeze,getSourceURL;$h͏_imports([["./commons.js", [["FERAL_REG_EXP",[$h͏_a => (FERAL_REG_EXP = $h͏_a)]],["SyntaxError",[$h͏_a => (SyntaxError = $h͏_a)]],["regexpExec",[$h͏_a => (regexpExec = $h͏_a)]],["regexpReplace",[$h͏_a => (regexpReplace = $h͏_a)]],["sealRegexp",[$h͏_a => (sealRegexp = $h͏_a)]],["stringSearch",[$h͏_a => (stringSearch = $h͏_a)]],["stringSlice",[$h͏_a => (stringSlice = $h͏_a)]],["stringSplit",[$h͏_a => (stringSplit = $h͏_a)]],["freeze",[$h͏_a => (freeze = $h͏_a)]]]],["./get-source-url.js", [["getSourceURL",[$h͏_a => (getSourceURL = $h͏_a)]]]]]);
|
|
8047
|
+
|
|
8047
8048
|
|
|
8048
8049
|
|
|
8049
8050
|
|
|
@@ -8154,9 +8155,79 @@ const htmlCommentPattern = sealRegexp(
|
|
|
8154
8155
|
// /////////////////////////////////////////////////////////////////////////////
|
|
8155
8156
|
$h͏_once.evadeHtmlCommentTest(evadeHtmlCommentTest);
|
|
8156
8157
|
const importPattern = sealRegexp(
|
|
8157
|
-
new FERAL_REG_EXP('(^|[^.]|\\.\\.\\.)\\bimport(\\s*(?:\\(
|
|
8158
|
+
new FERAL_REG_EXP('(^|[^.]|\\.\\.\\.)\\bimport(\\s*(?:\\(|\\.|/[/*]))', 'g'),
|
|
8159
|
+
);
|
|
8160
|
+
|
|
8161
|
+
/**
|
|
8162
|
+
* Matches one line of a run of `//# sourceURL=` and `//# sourceMappingURL=`
|
|
8163
|
+
* comments at the very end of the source (`sourceMetaTrailerStart` finds
|
|
8164
|
+
* the run), as module-source, compartment-mapper and
|
|
8165
|
+
* bundlers append to evaluated code (a module's location may well contain
|
|
8166
|
+
* `import.`, as in `conditional-import.js`).
|
|
8167
|
+
*
|
|
8168
|
+
* Each line must begin at a line start and its value must hold no whitespace
|
|
8169
|
+
* and none of `*`, backtick, `$`, quotes or backslash. Such a line is inert
|
|
8170
|
+
* wherever it stands: outside any literal it is a line comment; a regular
|
|
8171
|
+
* expression literal cannot span lines; and inside a block comment, a string
|
|
8172
|
+
* continued from the line before or a template literal, the line can neither
|
|
8173
|
+
* close that context (no `*`, quote or backtick) nor open a substitution (no
|
|
8174
|
+
* `$`). Since nothing but whitespace follows the run, an unclosed context
|
|
8175
|
+
* there is a SyntaxError. So `rejectImportExpressions` need not scan it.
|
|
8176
|
+
*
|
|
8177
|
+
* A `/*# sourceMappingURL=` block comment is not skipped but scanned like
|
|
8178
|
+
* any other code, which can only make the check stricter.
|
|
8179
|
+
*/
|
|
8180
|
+
const sourceMetaLinePattern = sealRegexp(
|
|
8181
|
+
new FERAL_REG_EXP('^//# source(?:Mapping)?URL=[^\\s*`$\'"\\\\]*$'),
|
|
8182
|
+
);
|
|
8183
|
+
|
|
8184
|
+
const whitespacePattern = sealRegexp(new FERAL_REG_EXP('^\\s$'));
|
|
8185
|
+
|
|
8186
|
+
const lineTerminatorPattern = sealRegexp(
|
|
8187
|
+
new FERAL_REG_EXP('^[\\n\\r\\u2028\\u2029]$'),
|
|
8158
8188
|
);
|
|
8159
8189
|
|
|
8190
|
+
/**
|
|
8191
|
+
* Returns the index at which the trailing run of source meta comments
|
|
8192
|
+
* begins, at its leading line terminator if it has one, or the length of
|
|
8193
|
+
* the source if there is no such run. It reads the source backward, one
|
|
8194
|
+
* line at a time, and tests each line with `sourceMetaLinePattern` alone,
|
|
8195
|
+
* so it takes time linear in the length of the source. A single regular
|
|
8196
|
+
* expression for the whole run, `(?:(?:^|[\n\r\u2028\u2029])<line>)+\s*$`,
|
|
8197
|
+
* finds the same run, but a search retries it at every line terminator,
|
|
8198
|
+
* which takes time quadratic in the number of lines of the run.
|
|
8199
|
+
*
|
|
8200
|
+
* @param {string} src
|
|
8201
|
+
* @returns {number}
|
|
8202
|
+
*/
|
|
8203
|
+
const sourceMetaTrailerStart = src => {
|
|
8204
|
+
let end = src.length;
|
|
8205
|
+
while (end > 0 && regexpExec(whitespacePattern, src[end - 1]) !== null) {
|
|
8206
|
+
end -= 1;
|
|
8207
|
+
}
|
|
8208
|
+
let start = src.length;
|
|
8209
|
+
for (;;) {
|
|
8210
|
+
let lineStart = end;
|
|
8211
|
+
while (
|
|
8212
|
+
lineStart > 0 &&
|
|
8213
|
+
regexpExec(lineTerminatorPattern, src[lineStart - 1]) === null
|
|
8214
|
+
) {
|
|
8215
|
+
lineStart -= 1;
|
|
8216
|
+
}
|
|
8217
|
+
if (
|
|
8218
|
+
regexpExec(sourceMetaLinePattern, stringSlice(src, lineStart, end)) ===
|
|
8219
|
+
null
|
|
8220
|
+
) {
|
|
8221
|
+
return start;
|
|
8222
|
+
}
|
|
8223
|
+
if (lineStart === 0) {
|
|
8224
|
+
return 0;
|
|
8225
|
+
}
|
|
8226
|
+
start = lineStart - 1;
|
|
8227
|
+
end = lineStart - 1;
|
|
8228
|
+
}
|
|
8229
|
+
};
|
|
8230
|
+
|
|
8160
8231
|
/**
|
|
8161
8232
|
* Conservatively reject the source text if it may contain a dynamic
|
|
8162
8233
|
* import expression. To reject without parsing, `rejectImportExpressions` will
|
|
@@ -8172,10 +8243,23 @@ const importPattern = sealRegexp(
|
|
|
8172
8243
|
* apparent import expressions in literal strings or comments.
|
|
8173
8244
|
*
|
|
8174
8245
|
* The current conservative rule looks for the identifier "import"
|
|
8175
|
-
* followed by either an open paren or something that looks like
|
|
8176
|
-
* beginning of a comment.
|
|
8177
|
-
*
|
|
8178
|
-
*
|
|
8246
|
+
* followed by either an open paren, a dot, or something that looks like
|
|
8247
|
+
* the beginning of a comment. The dot case rejects not just a
|
|
8248
|
+
* phase-qualified call such as `import.source(...)` or `import.defer(...)`,
|
|
8249
|
+
* but any property access under `import` at all, including `import.meta`,
|
|
8250
|
+
* regardless of whether the property is then called. This is broader than
|
|
8251
|
+
* strictly necessary: the substring "import." can occur incidentally, for
|
|
8252
|
+
* example in a module path or a comment, and such source text is rejected
|
|
8253
|
+
* too. That tradeoff is intentional: covering every `import.<name>` form,
|
|
8254
|
+
* called or not, without naming specific property names, is judged simpler
|
|
8255
|
+
* and safer than narrowing the match to the shape of a call. We assume that
|
|
8256
|
+
* we do not need to worry about html comment syntax because that was
|
|
8257
|
+
* already rejected by rejectHtmlComments.
|
|
8258
|
+
*
|
|
8259
|
+
* The scan stops short of a trailing run of `//# sourceURL=` or
|
|
8260
|
+
* `//# sourceMappingURL=` comments whose values could not end a comment,
|
|
8261
|
+
* string or template (see `sourceMetaTrailerStart`), so that a module
|
|
8262
|
+
* whose location contains `import.` still loads.
|
|
8179
8263
|
*
|
|
8180
8264
|
* this \s *must* match all kinds of syntax-defined whitespace. If e.g.
|
|
8181
8265
|
* U+2028 (LINE SEPARATOR) or U+2029 (PARAGRAPH SEPARATOR) is treated as
|
|
@@ -8188,7 +8272,8 @@ const importPattern = sealRegexp(
|
|
|
8188
8272
|
* @returns {string}
|
|
8189
8273
|
*/
|
|
8190
8274
|
const rejectImportExpressions = src => {
|
|
8191
|
-
const
|
|
8275
|
+
const scanned = stringSlice(src, 0, sourceMetaTrailerStart(src));
|
|
8276
|
+
const lineNumber = getLineNumber(scanned, importPattern);
|
|
8192
8277
|
if (lineNumber < 0) {
|
|
8193
8278
|
return src;
|
|
8194
8279
|
}
|
package/dist/lockdown.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// ses@1.15.
|
|
1
|
+
// ses@1.15.1
|
|
2
2
|
(functors => options => {
|
|
3
3
|
'use strict';
|
|
4
4
|
|
|
@@ -8043,7 +8043,8 @@ const sourceMetaEntriesRegExp = new FERAL_REG_EXP(
|
|
|
8043
8043
|
})()
|
|
8044
8044
|
,
|
|
8045
8045
|
// === 33. ses ./src/transforms.js ===
|
|
8046
|
-
({imports:$h͏_imports,liveVar:$h͏_live,onceVar:$h͏_once,import:$h͏_import,importMeta:$h͏____meta})=>(function(){'use strict';let FERAL_REG_EXP,SyntaxError,regexpReplace,sealRegexp,stringSearch,stringSlice,stringSplit,freeze,getSourceURL;$h͏_imports([["./commons.js", [["FERAL_REG_EXP",[$h͏_a => (FERAL_REG_EXP = $h͏_a)]],["SyntaxError",[$h͏_a => (SyntaxError = $h͏_a)]],["regexpReplace",[$h͏_a => (regexpReplace = $h͏_a)]],["sealRegexp",[$h͏_a => (sealRegexp = $h͏_a)]],["stringSearch",[$h͏_a => (stringSearch = $h͏_a)]],["stringSlice",[$h͏_a => (stringSlice = $h͏_a)]],["stringSplit",[$h͏_a => (stringSplit = $h͏_a)]],["freeze",[$h͏_a => (freeze = $h͏_a)]]]],["./get-source-url.js", [["getSourceURL",[$h͏_a => (getSourceURL = $h͏_a)]]]]]);
|
|
8046
|
+
({imports:$h͏_imports,liveVar:$h͏_live,onceVar:$h͏_once,import:$h͏_import,importMeta:$h͏____meta})=>(function(){'use strict';let FERAL_REG_EXP,SyntaxError,regexpExec,regexpReplace,sealRegexp,stringSearch,stringSlice,stringSplit,freeze,getSourceURL;$h͏_imports([["./commons.js", [["FERAL_REG_EXP",[$h͏_a => (FERAL_REG_EXP = $h͏_a)]],["SyntaxError",[$h͏_a => (SyntaxError = $h͏_a)]],["regexpExec",[$h͏_a => (regexpExec = $h͏_a)]],["regexpReplace",[$h͏_a => (regexpReplace = $h͏_a)]],["sealRegexp",[$h͏_a => (sealRegexp = $h͏_a)]],["stringSearch",[$h͏_a => (stringSearch = $h͏_a)]],["stringSlice",[$h͏_a => (stringSlice = $h͏_a)]],["stringSplit",[$h͏_a => (stringSplit = $h͏_a)]],["freeze",[$h͏_a => (freeze = $h͏_a)]]]],["./get-source-url.js", [["getSourceURL",[$h͏_a => (getSourceURL = $h͏_a)]]]]]);
|
|
8047
|
+
|
|
8047
8048
|
|
|
8048
8049
|
|
|
8049
8050
|
|
|
@@ -8154,9 +8155,79 @@ const htmlCommentPattern = sealRegexp(
|
|
|
8154
8155
|
// /////////////////////////////////////////////////////////////////////////////
|
|
8155
8156
|
$h͏_once.evadeHtmlCommentTest(evadeHtmlCommentTest);
|
|
8156
8157
|
const importPattern = sealRegexp(
|
|
8157
|
-
new FERAL_REG_EXP('(^|[^.]|\\.\\.\\.)\\bimport(\\s*(?:\\(
|
|
8158
|
+
new FERAL_REG_EXP('(^|[^.]|\\.\\.\\.)\\bimport(\\s*(?:\\(|\\.|/[/*]))', 'g'),
|
|
8159
|
+
);
|
|
8160
|
+
|
|
8161
|
+
/**
|
|
8162
|
+
* Matches one line of a run of `//# sourceURL=` and `//# sourceMappingURL=`
|
|
8163
|
+
* comments at the very end of the source (`sourceMetaTrailerStart` finds
|
|
8164
|
+
* the run), as module-source, compartment-mapper and
|
|
8165
|
+
* bundlers append to evaluated code (a module's location may well contain
|
|
8166
|
+
* `import.`, as in `conditional-import.js`).
|
|
8167
|
+
*
|
|
8168
|
+
* Each line must begin at a line start and its value must hold no whitespace
|
|
8169
|
+
* and none of `*`, backtick, `$`, quotes or backslash. Such a line is inert
|
|
8170
|
+
* wherever it stands: outside any literal it is a line comment; a regular
|
|
8171
|
+
* expression literal cannot span lines; and inside a block comment, a string
|
|
8172
|
+
* continued from the line before or a template literal, the line can neither
|
|
8173
|
+
* close that context (no `*`, quote or backtick) nor open a substitution (no
|
|
8174
|
+
* `$`). Since nothing but whitespace follows the run, an unclosed context
|
|
8175
|
+
* there is a SyntaxError. So `rejectImportExpressions` need not scan it.
|
|
8176
|
+
*
|
|
8177
|
+
* A `/*# sourceMappingURL=` block comment is not skipped but scanned like
|
|
8178
|
+
* any other code, which can only make the check stricter.
|
|
8179
|
+
*/
|
|
8180
|
+
const sourceMetaLinePattern = sealRegexp(
|
|
8181
|
+
new FERAL_REG_EXP('^//# source(?:Mapping)?URL=[^\\s*`$\'"\\\\]*$'),
|
|
8182
|
+
);
|
|
8183
|
+
|
|
8184
|
+
const whitespacePattern = sealRegexp(new FERAL_REG_EXP('^\\s$'));
|
|
8185
|
+
|
|
8186
|
+
const lineTerminatorPattern = sealRegexp(
|
|
8187
|
+
new FERAL_REG_EXP('^[\\n\\r\\u2028\\u2029]$'),
|
|
8158
8188
|
);
|
|
8159
8189
|
|
|
8190
|
+
/**
|
|
8191
|
+
* Returns the index at which the trailing run of source meta comments
|
|
8192
|
+
* begins, at its leading line terminator if it has one, or the length of
|
|
8193
|
+
* the source if there is no such run. It reads the source backward, one
|
|
8194
|
+
* line at a time, and tests each line with `sourceMetaLinePattern` alone,
|
|
8195
|
+
* so it takes time linear in the length of the source. A single regular
|
|
8196
|
+
* expression for the whole run, `(?:(?:^|[\n\r\u2028\u2029])<line>)+\s*$`,
|
|
8197
|
+
* finds the same run, but a search retries it at every line terminator,
|
|
8198
|
+
* which takes time quadratic in the number of lines of the run.
|
|
8199
|
+
*
|
|
8200
|
+
* @param {string} src
|
|
8201
|
+
* @returns {number}
|
|
8202
|
+
*/
|
|
8203
|
+
const sourceMetaTrailerStart = src => {
|
|
8204
|
+
let end = src.length;
|
|
8205
|
+
while (end > 0 && regexpExec(whitespacePattern, src[end - 1]) !== null) {
|
|
8206
|
+
end -= 1;
|
|
8207
|
+
}
|
|
8208
|
+
let start = src.length;
|
|
8209
|
+
for (;;) {
|
|
8210
|
+
let lineStart = end;
|
|
8211
|
+
while (
|
|
8212
|
+
lineStart > 0 &&
|
|
8213
|
+
regexpExec(lineTerminatorPattern, src[lineStart - 1]) === null
|
|
8214
|
+
) {
|
|
8215
|
+
lineStart -= 1;
|
|
8216
|
+
}
|
|
8217
|
+
if (
|
|
8218
|
+
regexpExec(sourceMetaLinePattern, stringSlice(src, lineStart, end)) ===
|
|
8219
|
+
null
|
|
8220
|
+
) {
|
|
8221
|
+
return start;
|
|
8222
|
+
}
|
|
8223
|
+
if (lineStart === 0) {
|
|
8224
|
+
return 0;
|
|
8225
|
+
}
|
|
8226
|
+
start = lineStart - 1;
|
|
8227
|
+
end = lineStart - 1;
|
|
8228
|
+
}
|
|
8229
|
+
};
|
|
8230
|
+
|
|
8160
8231
|
/**
|
|
8161
8232
|
* Conservatively reject the source text if it may contain a dynamic
|
|
8162
8233
|
* import expression. To reject without parsing, `rejectImportExpressions` will
|
|
@@ -8172,10 +8243,23 @@ const importPattern = sealRegexp(
|
|
|
8172
8243
|
* apparent import expressions in literal strings or comments.
|
|
8173
8244
|
*
|
|
8174
8245
|
* The current conservative rule looks for the identifier "import"
|
|
8175
|
-
* followed by either an open paren or something that looks like
|
|
8176
|
-
* beginning of a comment.
|
|
8177
|
-
*
|
|
8178
|
-
*
|
|
8246
|
+
* followed by either an open paren, a dot, or something that looks like
|
|
8247
|
+
* the beginning of a comment. The dot case rejects not just a
|
|
8248
|
+
* phase-qualified call such as `import.source(...)` or `import.defer(...)`,
|
|
8249
|
+
* but any property access under `import` at all, including `import.meta`,
|
|
8250
|
+
* regardless of whether the property is then called. This is broader than
|
|
8251
|
+
* strictly necessary: the substring "import." can occur incidentally, for
|
|
8252
|
+
* example in a module path or a comment, and such source text is rejected
|
|
8253
|
+
* too. That tradeoff is intentional: covering every `import.<name>` form,
|
|
8254
|
+
* called or not, without naming specific property names, is judged simpler
|
|
8255
|
+
* and safer than narrowing the match to the shape of a call. We assume that
|
|
8256
|
+
* we do not need to worry about html comment syntax because that was
|
|
8257
|
+
* already rejected by rejectHtmlComments.
|
|
8258
|
+
*
|
|
8259
|
+
* The scan stops short of a trailing run of `//# sourceURL=` or
|
|
8260
|
+
* `//# sourceMappingURL=` comments whose values could not end a comment,
|
|
8261
|
+
* string or template (see `sourceMetaTrailerStart`), so that a module
|
|
8262
|
+
* whose location contains `import.` still loads.
|
|
8179
8263
|
*
|
|
8180
8264
|
* this \s *must* match all kinds of syntax-defined whitespace. If e.g.
|
|
8181
8265
|
* U+2028 (LINE SEPARATOR) or U+2029 (PARAGRAPH SEPARATOR) is treated as
|
|
@@ -8188,7 +8272,8 @@ const importPattern = sealRegexp(
|
|
|
8188
8272
|
* @returns {string}
|
|
8189
8273
|
*/
|
|
8190
8274
|
const rejectImportExpressions = src => {
|
|
8191
|
-
const
|
|
8275
|
+
const scanned = stringSlice(src, 0, sourceMetaTrailerStart(src));
|
|
8276
|
+
const lineNumber = getLineNumber(scanned, importPattern);
|
|
8192
8277
|
if (lineNumber < 0) {
|
|
8193
8278
|
return src;
|
|
8194
8279
|
}
|
package/dist/lockdown.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// ses@1.15.
|
|
1
|
+
// ses@1.15.1
|
|
2
2
|
(functors => options => {
|
|
3
3
|
'use strict';
|
|
4
4
|
|
|
@@ -8043,7 +8043,8 @@ const sourceMetaEntriesRegExp = new FERAL_REG_EXP(
|
|
|
8043
8043
|
})()
|
|
8044
8044
|
,
|
|
8045
8045
|
// === 33. ses ./src/transforms.js ===
|
|
8046
|
-
({imports:$h͏_imports,liveVar:$h͏_live,onceVar:$h͏_once,import:$h͏_import,importMeta:$h͏____meta})=>(function(){'use strict';let FERAL_REG_EXP,SyntaxError,regexpReplace,sealRegexp,stringSearch,stringSlice,stringSplit,freeze,getSourceURL;$h͏_imports([["./commons.js", [["FERAL_REG_EXP",[$h͏_a => (FERAL_REG_EXP = $h͏_a)]],["SyntaxError",[$h͏_a => (SyntaxError = $h͏_a)]],["regexpReplace",[$h͏_a => (regexpReplace = $h͏_a)]],["sealRegexp",[$h͏_a => (sealRegexp = $h͏_a)]],["stringSearch",[$h͏_a => (stringSearch = $h͏_a)]],["stringSlice",[$h͏_a => (stringSlice = $h͏_a)]],["stringSplit",[$h͏_a => (stringSplit = $h͏_a)]],["freeze",[$h͏_a => (freeze = $h͏_a)]]]],["./get-source-url.js", [["getSourceURL",[$h͏_a => (getSourceURL = $h͏_a)]]]]]);
|
|
8046
|
+
({imports:$h͏_imports,liveVar:$h͏_live,onceVar:$h͏_once,import:$h͏_import,importMeta:$h͏____meta})=>(function(){'use strict';let FERAL_REG_EXP,SyntaxError,regexpExec,regexpReplace,sealRegexp,stringSearch,stringSlice,stringSplit,freeze,getSourceURL;$h͏_imports([["./commons.js", [["FERAL_REG_EXP",[$h͏_a => (FERAL_REG_EXP = $h͏_a)]],["SyntaxError",[$h͏_a => (SyntaxError = $h͏_a)]],["regexpExec",[$h͏_a => (regexpExec = $h͏_a)]],["regexpReplace",[$h͏_a => (regexpReplace = $h͏_a)]],["sealRegexp",[$h͏_a => (sealRegexp = $h͏_a)]],["stringSearch",[$h͏_a => (stringSearch = $h͏_a)]],["stringSlice",[$h͏_a => (stringSlice = $h͏_a)]],["stringSplit",[$h͏_a => (stringSplit = $h͏_a)]],["freeze",[$h͏_a => (freeze = $h͏_a)]]]],["./get-source-url.js", [["getSourceURL",[$h͏_a => (getSourceURL = $h͏_a)]]]]]);
|
|
8047
|
+
|
|
8047
8048
|
|
|
8048
8049
|
|
|
8049
8050
|
|
|
@@ -8154,9 +8155,79 @@ const htmlCommentPattern = sealRegexp(
|
|
|
8154
8155
|
// /////////////////////////////////////////////////////////////////////////////
|
|
8155
8156
|
$h͏_once.evadeHtmlCommentTest(evadeHtmlCommentTest);
|
|
8156
8157
|
const importPattern = sealRegexp(
|
|
8157
|
-
new FERAL_REG_EXP('(^|[^.]|\\.\\.\\.)\\bimport(\\s*(?:\\(
|
|
8158
|
+
new FERAL_REG_EXP('(^|[^.]|\\.\\.\\.)\\bimport(\\s*(?:\\(|\\.|/[/*]))', 'g'),
|
|
8159
|
+
);
|
|
8160
|
+
|
|
8161
|
+
/**
|
|
8162
|
+
* Matches one line of a run of `//# sourceURL=` and `//# sourceMappingURL=`
|
|
8163
|
+
* comments at the very end of the source (`sourceMetaTrailerStart` finds
|
|
8164
|
+
* the run), as module-source, compartment-mapper and
|
|
8165
|
+
* bundlers append to evaluated code (a module's location may well contain
|
|
8166
|
+
* `import.`, as in `conditional-import.js`).
|
|
8167
|
+
*
|
|
8168
|
+
* Each line must begin at a line start and its value must hold no whitespace
|
|
8169
|
+
* and none of `*`, backtick, `$`, quotes or backslash. Such a line is inert
|
|
8170
|
+
* wherever it stands: outside any literal it is a line comment; a regular
|
|
8171
|
+
* expression literal cannot span lines; and inside a block comment, a string
|
|
8172
|
+
* continued from the line before or a template literal, the line can neither
|
|
8173
|
+
* close that context (no `*`, quote or backtick) nor open a substitution (no
|
|
8174
|
+
* `$`). Since nothing but whitespace follows the run, an unclosed context
|
|
8175
|
+
* there is a SyntaxError. So `rejectImportExpressions` need not scan it.
|
|
8176
|
+
*
|
|
8177
|
+
* A `/*# sourceMappingURL=` block comment is not skipped but scanned like
|
|
8178
|
+
* any other code, which can only make the check stricter.
|
|
8179
|
+
*/
|
|
8180
|
+
const sourceMetaLinePattern = sealRegexp(
|
|
8181
|
+
new FERAL_REG_EXP('^//# source(?:Mapping)?URL=[^\\s*`$\'"\\\\]*$'),
|
|
8182
|
+
);
|
|
8183
|
+
|
|
8184
|
+
const whitespacePattern = sealRegexp(new FERAL_REG_EXP('^\\s$'));
|
|
8185
|
+
|
|
8186
|
+
const lineTerminatorPattern = sealRegexp(
|
|
8187
|
+
new FERAL_REG_EXP('^[\\n\\r\\u2028\\u2029]$'),
|
|
8158
8188
|
);
|
|
8159
8189
|
|
|
8190
|
+
/**
|
|
8191
|
+
* Returns the index at which the trailing run of source meta comments
|
|
8192
|
+
* begins, at its leading line terminator if it has one, or the length of
|
|
8193
|
+
* the source if there is no such run. It reads the source backward, one
|
|
8194
|
+
* line at a time, and tests each line with `sourceMetaLinePattern` alone,
|
|
8195
|
+
* so it takes time linear in the length of the source. A single regular
|
|
8196
|
+
* expression for the whole run, `(?:(?:^|[\n\r\u2028\u2029])<line>)+\s*$`,
|
|
8197
|
+
* finds the same run, but a search retries it at every line terminator,
|
|
8198
|
+
* which takes time quadratic in the number of lines of the run.
|
|
8199
|
+
*
|
|
8200
|
+
* @param {string} src
|
|
8201
|
+
* @returns {number}
|
|
8202
|
+
*/
|
|
8203
|
+
const sourceMetaTrailerStart = src => {
|
|
8204
|
+
let end = src.length;
|
|
8205
|
+
while (end > 0 && regexpExec(whitespacePattern, src[end - 1]) !== null) {
|
|
8206
|
+
end -= 1;
|
|
8207
|
+
}
|
|
8208
|
+
let start = src.length;
|
|
8209
|
+
for (;;) {
|
|
8210
|
+
let lineStart = end;
|
|
8211
|
+
while (
|
|
8212
|
+
lineStart > 0 &&
|
|
8213
|
+
regexpExec(lineTerminatorPattern, src[lineStart - 1]) === null
|
|
8214
|
+
) {
|
|
8215
|
+
lineStart -= 1;
|
|
8216
|
+
}
|
|
8217
|
+
if (
|
|
8218
|
+
regexpExec(sourceMetaLinePattern, stringSlice(src, lineStart, end)) ===
|
|
8219
|
+
null
|
|
8220
|
+
) {
|
|
8221
|
+
return start;
|
|
8222
|
+
}
|
|
8223
|
+
if (lineStart === 0) {
|
|
8224
|
+
return 0;
|
|
8225
|
+
}
|
|
8226
|
+
start = lineStart - 1;
|
|
8227
|
+
end = lineStart - 1;
|
|
8228
|
+
}
|
|
8229
|
+
};
|
|
8230
|
+
|
|
8160
8231
|
/**
|
|
8161
8232
|
* Conservatively reject the source text if it may contain a dynamic
|
|
8162
8233
|
* import expression. To reject without parsing, `rejectImportExpressions` will
|
|
@@ -8172,10 +8243,23 @@ const importPattern = sealRegexp(
|
|
|
8172
8243
|
* apparent import expressions in literal strings or comments.
|
|
8173
8244
|
*
|
|
8174
8245
|
* The current conservative rule looks for the identifier "import"
|
|
8175
|
-
* followed by either an open paren or something that looks like
|
|
8176
|
-
* beginning of a comment.
|
|
8177
|
-
*
|
|
8178
|
-
*
|
|
8246
|
+
* followed by either an open paren, a dot, or something that looks like
|
|
8247
|
+
* the beginning of a comment. The dot case rejects not just a
|
|
8248
|
+
* phase-qualified call such as `import.source(...)` or `import.defer(...)`,
|
|
8249
|
+
* but any property access under `import` at all, including `import.meta`,
|
|
8250
|
+
* regardless of whether the property is then called. This is broader than
|
|
8251
|
+
* strictly necessary: the substring "import." can occur incidentally, for
|
|
8252
|
+
* example in a module path or a comment, and such source text is rejected
|
|
8253
|
+
* too. That tradeoff is intentional: covering every `import.<name>` form,
|
|
8254
|
+
* called or not, without naming specific property names, is judged simpler
|
|
8255
|
+
* and safer than narrowing the match to the shape of a call. We assume that
|
|
8256
|
+
* we do not need to worry about html comment syntax because that was
|
|
8257
|
+
* already rejected by rejectHtmlComments.
|
|
8258
|
+
*
|
|
8259
|
+
* The scan stops short of a trailing run of `//# sourceURL=` or
|
|
8260
|
+
* `//# sourceMappingURL=` comments whose values could not end a comment,
|
|
8261
|
+
* string or template (see `sourceMetaTrailerStart`), so that a module
|
|
8262
|
+
* whose location contains `import.` still loads.
|
|
8179
8263
|
*
|
|
8180
8264
|
* this \s *must* match all kinds of syntax-defined whitespace. If e.g.
|
|
8181
8265
|
* U+2028 (LINE SEPARATOR) or U+2029 (PARAGRAPH SEPARATOR) is treated as
|
|
@@ -8188,7 +8272,8 @@ const importPattern = sealRegexp(
|
|
|
8188
8272
|
* @returns {string}
|
|
8189
8273
|
*/
|
|
8190
8274
|
const rejectImportExpressions = src => {
|
|
8191
|
-
const
|
|
8275
|
+
const scanned = stringSlice(src, 0, sourceMetaTrailerStart(src));
|
|
8276
|
+
const lineNumber = getLineNumber(scanned, importPattern);
|
|
8192
8277
|
if (lineNumber < 0) {
|
|
8193
8278
|
return src;
|
|
8194
8279
|
}
|