ses 0.18.8 → 0.18.9
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 +90 -7
- package/dist/lockdown.mjs +90 -7
- package/dist/lockdown.umd.js +90 -7
- package/dist/lockdown.umd.min.js +1 -1
- package/dist/ses.cjs +90 -7
- package/dist/ses.mjs +90 -7
- package/dist/ses.umd.js +90 -7
- package/dist/ses.umd.min.js +1 -1
- package/package.json +2 -2
- package/src/transforms.js +89 -6
package/dist/lockdown.cjs
CHANGED
|
@@ -5596,7 +5596,8 @@ const getSourceURL= (src)=>{
|
|
|
5596
5596
|
})
|
|
5597
5597
|
,
|
|
5598
5598
|
// === functors[27] ===
|
|
5599
|
-
(({ imports: $h_imports, liveVar: $h_live, onceVar: $h_once, importMeta: $h____meta, }) => { let FERAL_REG_EXP,SyntaxError,stringReplace,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)]],["stringReplace", [$h_a => (stringReplace = $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)]]]]]);
|
|
5599
|
+
(({ imports: $h_imports, liveVar: $h_live, onceVar: $h_once, importMeta: $h____meta, }) => { let FERAL_REG_EXP,SyntaxError,regexpExec,stringReplace,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)]],["stringReplace", [$h_a => (stringReplace = $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)]]]]]);
|
|
5600
|
+
|
|
5600
5601
|
|
|
5601
5602
|
|
|
5602
5603
|
|
|
@@ -5704,10 +5705,78 @@ const evadeHtmlCommentTest= (src)=>{
|
|
|
5704
5705
|
// /////////////////////////////////////////////////////////////////////////////
|
|
5705
5706
|
$h_once.evadeHtmlCommentTest(evadeHtmlCommentTest);
|
|
5706
5707
|
const importPattern= new FERAL_REG_EXP(
|
|
5707
|
-
'(^|[^.]|\\.\\.\\.)\\bimport(\\s*(?:\\(
|
|
5708
|
+
'(^|[^.]|\\.\\.\\.)\\bimport(\\s*(?:\\(|\\.|/[/*]))',
|
|
5708
5709
|
'g');
|
|
5709
5710
|
|
|
5710
5711
|
|
|
5712
|
+
/**
|
|
5713
|
+
* Matches one line of a run of `//# sourceURL=` and `//# sourceMappingURL=`
|
|
5714
|
+
* comments at the very end of the source (`sourceMetaTrailerStart` finds
|
|
5715
|
+
* the run), as module-source, compartment-mapper and
|
|
5716
|
+
* bundlers append to evaluated code (a module's location may well contain
|
|
5717
|
+
* `import.`, as in `conditional-import.js`).
|
|
5718
|
+
*
|
|
5719
|
+
* Each line must begin at a line start and its value must hold no whitespace
|
|
5720
|
+
* and none of `*`, backtick, `$`, quotes or backslash. Such a line is inert
|
|
5721
|
+
* wherever it stands: outside any literal it is a line comment; a regular
|
|
5722
|
+
* expression literal cannot span lines; and inside a block comment, a string
|
|
5723
|
+
* continued from the line before or a template literal, the line can neither
|
|
5724
|
+
* close that context (no `*`, quote or backtick) nor open a substitution (no
|
|
5725
|
+
* `$`). Since nothing but whitespace follows the run, an unclosed context
|
|
5726
|
+
* there is a SyntaxError. So `rejectImportExpressions` need not scan it.
|
|
5727
|
+
*
|
|
5728
|
+
* A `/*# sourceMappingURL=` block comment is not skipped but scanned like
|
|
5729
|
+
* any other code, which can only make the check stricter.
|
|
5730
|
+
*/
|
|
5731
|
+
const sourceMetaLinePattern= new FERAL_REG_EXP(
|
|
5732
|
+
'^//# source(?:Mapping)?URL=[^\\s*`$\'"\\\\]*$');
|
|
5733
|
+
|
|
5734
|
+
|
|
5735
|
+
const whitespacePattern= new FERAL_REG_EXP('^\\s$');
|
|
5736
|
+
|
|
5737
|
+
const lineTerminatorPattern= new FERAL_REG_EXP('^[\\n\\r\\u2028\\u2029]$');
|
|
5738
|
+
|
|
5739
|
+
/**
|
|
5740
|
+
* Returns the index at which the trailing run of source meta comments
|
|
5741
|
+
* begins, at its leading line terminator if it has one, or the length of
|
|
5742
|
+
* the source if there is no such run. It reads the source backward, one
|
|
5743
|
+
* line at a time, and tests each line with `sourceMetaLinePattern` alone,
|
|
5744
|
+
* so it takes time linear in the length of the source. A single regular
|
|
5745
|
+
* expression for the whole run, `(?:(?:^|[\n\r\u2028\u2029])<line>)+\s*$`,
|
|
5746
|
+
* finds the same run, but a search retries it at every line terminator,
|
|
5747
|
+
* which takes time quadratic in the number of lines of the run.
|
|
5748
|
+
*
|
|
5749
|
+
* @param {string} src
|
|
5750
|
+
* @returns {number}
|
|
5751
|
+
*/
|
|
5752
|
+
const sourceMetaTrailerStart= (src)=>{
|
|
5753
|
+
let end= src.length;
|
|
5754
|
+
while( end> 0&& regexpExec(whitespacePattern, src[end- 1])!== null) {
|
|
5755
|
+
end-= 1;
|
|
5756
|
+
}
|
|
5757
|
+
let start= src.length;
|
|
5758
|
+
for(;;) {
|
|
5759
|
+
let lineStart= end;
|
|
5760
|
+
while(
|
|
5761
|
+
lineStart> 0&&
|
|
5762
|
+
regexpExec(lineTerminatorPattern, src[lineStart- 1])=== null)
|
|
5763
|
+
{
|
|
5764
|
+
lineStart-= 1;
|
|
5765
|
+
}
|
|
5766
|
+
if(
|
|
5767
|
+
regexpExec(sourceMetaLinePattern, stringSlice(src, lineStart, end))===
|
|
5768
|
+
null)
|
|
5769
|
+
{
|
|
5770
|
+
return start;
|
|
5771
|
+
}
|
|
5772
|
+
if( lineStart=== 0) {
|
|
5773
|
+
return 0;
|
|
5774
|
+
}
|
|
5775
|
+
start= lineStart- 1;
|
|
5776
|
+
end= lineStart- 1;
|
|
5777
|
+
}
|
|
5778
|
+
};
|
|
5779
|
+
|
|
5711
5780
|
/**
|
|
5712
5781
|
* Conservatively reject the source text if it may contain a dynamic
|
|
5713
5782
|
* import expression. To reject without parsing, `rejectImportExpressions` will
|
|
@@ -5723,10 +5792,23 @@ const importPattern= new FERAL_REG_EXP(
|
|
|
5723
5792
|
* apparent import expressions in literal strings or comments.
|
|
5724
5793
|
*
|
|
5725
5794
|
* The current conservative rule looks for the identifier "import"
|
|
5726
|
-
* followed by either an open paren or something that looks like
|
|
5727
|
-
* beginning of a comment.
|
|
5728
|
-
*
|
|
5729
|
-
*
|
|
5795
|
+
* followed by either an open paren, a dot, or something that looks like
|
|
5796
|
+
* the beginning of a comment. The dot case rejects not just a
|
|
5797
|
+
* phase-qualified call such as `import.source(...)` or `import.defer(...)`,
|
|
5798
|
+
* but any property access under `import` at all, including `import.meta`,
|
|
5799
|
+
* regardless of whether the property is then called. This is broader than
|
|
5800
|
+
* strictly necessary: the substring "import." can occur incidentally, for
|
|
5801
|
+
* example in a module path or a comment, and such source text is rejected
|
|
5802
|
+
* too. That tradeoff is intentional: covering every `import.<name>` form,
|
|
5803
|
+
* called or not, without naming specific property names, is judged simpler
|
|
5804
|
+
* and safer than narrowing the match to the shape of a call. We assume that
|
|
5805
|
+
* we do not need to worry about html comment syntax because that was
|
|
5806
|
+
* already rejected by rejectHtmlComments.
|
|
5807
|
+
*
|
|
5808
|
+
* The scan stops short of a trailing run of `//# sourceURL=` or
|
|
5809
|
+
* `//# sourceMappingURL=` comments whose values could not end a comment,
|
|
5810
|
+
* string or template (see `sourceMetaTrailerStart`), so that a module
|
|
5811
|
+
* whose location contains `import.` still loads.
|
|
5730
5812
|
*
|
|
5731
5813
|
* this \s *must* match all kinds of syntax-defined whitespace. If e.g.
|
|
5732
5814
|
* U+2028 (LINE SEPARATOR) or U+2029 (PARAGRAPH SEPARATOR) is treated as
|
|
@@ -5739,7 +5821,8 @@ const importPattern= new FERAL_REG_EXP(
|
|
|
5739
5821
|
* @returns {string}
|
|
5740
5822
|
*/
|
|
5741
5823
|
const rejectImportExpressions= (src)=>{
|
|
5742
|
-
const
|
|
5824
|
+
const scanned= stringSlice(src, 0, sourceMetaTrailerStart(src));
|
|
5825
|
+
const lineNumber= getLineNumber(scanned, importPattern);
|
|
5743
5826
|
if( lineNumber< 0) {
|
|
5744
5827
|
return src;
|
|
5745
5828
|
}
|
package/dist/lockdown.mjs
CHANGED
|
@@ -5596,7 +5596,8 @@ const getSourceURL= (src)=>{
|
|
|
5596
5596
|
})
|
|
5597
5597
|
,
|
|
5598
5598
|
// === functors[27] ===
|
|
5599
|
-
(({ imports: $h_imports, liveVar: $h_live, onceVar: $h_once, importMeta: $h____meta, }) => { let FERAL_REG_EXP,SyntaxError,stringReplace,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)]],["stringReplace", [$h_a => (stringReplace = $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)]]]]]);
|
|
5599
|
+
(({ imports: $h_imports, liveVar: $h_live, onceVar: $h_once, importMeta: $h____meta, }) => { let FERAL_REG_EXP,SyntaxError,regexpExec,stringReplace,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)]],["stringReplace", [$h_a => (stringReplace = $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)]]]]]);
|
|
5600
|
+
|
|
5600
5601
|
|
|
5601
5602
|
|
|
5602
5603
|
|
|
@@ -5704,10 +5705,78 @@ const evadeHtmlCommentTest= (src)=>{
|
|
|
5704
5705
|
// /////////////////////////////////////////////////////////////////////////////
|
|
5705
5706
|
$h_once.evadeHtmlCommentTest(evadeHtmlCommentTest);
|
|
5706
5707
|
const importPattern= new FERAL_REG_EXP(
|
|
5707
|
-
'(^|[^.]|\\.\\.\\.)\\bimport(\\s*(?:\\(
|
|
5708
|
+
'(^|[^.]|\\.\\.\\.)\\bimport(\\s*(?:\\(|\\.|/[/*]))',
|
|
5708
5709
|
'g');
|
|
5709
5710
|
|
|
5710
5711
|
|
|
5712
|
+
/**
|
|
5713
|
+
* Matches one line of a run of `//# sourceURL=` and `//# sourceMappingURL=`
|
|
5714
|
+
* comments at the very end of the source (`sourceMetaTrailerStart` finds
|
|
5715
|
+
* the run), as module-source, compartment-mapper and
|
|
5716
|
+
* bundlers append to evaluated code (a module's location may well contain
|
|
5717
|
+
* `import.`, as in `conditional-import.js`).
|
|
5718
|
+
*
|
|
5719
|
+
* Each line must begin at a line start and its value must hold no whitespace
|
|
5720
|
+
* and none of `*`, backtick, `$`, quotes or backslash. Such a line is inert
|
|
5721
|
+
* wherever it stands: outside any literal it is a line comment; a regular
|
|
5722
|
+
* expression literal cannot span lines; and inside a block comment, a string
|
|
5723
|
+
* continued from the line before or a template literal, the line can neither
|
|
5724
|
+
* close that context (no `*`, quote or backtick) nor open a substitution (no
|
|
5725
|
+
* `$`). Since nothing but whitespace follows the run, an unclosed context
|
|
5726
|
+
* there is a SyntaxError. So `rejectImportExpressions` need not scan it.
|
|
5727
|
+
*
|
|
5728
|
+
* A `/*# sourceMappingURL=` block comment is not skipped but scanned like
|
|
5729
|
+
* any other code, which can only make the check stricter.
|
|
5730
|
+
*/
|
|
5731
|
+
const sourceMetaLinePattern= new FERAL_REG_EXP(
|
|
5732
|
+
'^//# source(?:Mapping)?URL=[^\\s*`$\'"\\\\]*$');
|
|
5733
|
+
|
|
5734
|
+
|
|
5735
|
+
const whitespacePattern= new FERAL_REG_EXP('^\\s$');
|
|
5736
|
+
|
|
5737
|
+
const lineTerminatorPattern= new FERAL_REG_EXP('^[\\n\\r\\u2028\\u2029]$');
|
|
5738
|
+
|
|
5739
|
+
/**
|
|
5740
|
+
* Returns the index at which the trailing run of source meta comments
|
|
5741
|
+
* begins, at its leading line terminator if it has one, or the length of
|
|
5742
|
+
* the source if there is no such run. It reads the source backward, one
|
|
5743
|
+
* line at a time, and tests each line with `sourceMetaLinePattern` alone,
|
|
5744
|
+
* so it takes time linear in the length of the source. A single regular
|
|
5745
|
+
* expression for the whole run, `(?:(?:^|[\n\r\u2028\u2029])<line>)+\s*$`,
|
|
5746
|
+
* finds the same run, but a search retries it at every line terminator,
|
|
5747
|
+
* which takes time quadratic in the number of lines of the run.
|
|
5748
|
+
*
|
|
5749
|
+
* @param {string} src
|
|
5750
|
+
* @returns {number}
|
|
5751
|
+
*/
|
|
5752
|
+
const sourceMetaTrailerStart= (src)=>{
|
|
5753
|
+
let end= src.length;
|
|
5754
|
+
while( end> 0&& regexpExec(whitespacePattern, src[end- 1])!== null) {
|
|
5755
|
+
end-= 1;
|
|
5756
|
+
}
|
|
5757
|
+
let start= src.length;
|
|
5758
|
+
for(;;) {
|
|
5759
|
+
let lineStart= end;
|
|
5760
|
+
while(
|
|
5761
|
+
lineStart> 0&&
|
|
5762
|
+
regexpExec(lineTerminatorPattern, src[lineStart- 1])=== null)
|
|
5763
|
+
{
|
|
5764
|
+
lineStart-= 1;
|
|
5765
|
+
}
|
|
5766
|
+
if(
|
|
5767
|
+
regexpExec(sourceMetaLinePattern, stringSlice(src, lineStart, end))===
|
|
5768
|
+
null)
|
|
5769
|
+
{
|
|
5770
|
+
return start;
|
|
5771
|
+
}
|
|
5772
|
+
if( lineStart=== 0) {
|
|
5773
|
+
return 0;
|
|
5774
|
+
}
|
|
5775
|
+
start= lineStart- 1;
|
|
5776
|
+
end= lineStart- 1;
|
|
5777
|
+
}
|
|
5778
|
+
};
|
|
5779
|
+
|
|
5711
5780
|
/**
|
|
5712
5781
|
* Conservatively reject the source text if it may contain a dynamic
|
|
5713
5782
|
* import expression. To reject without parsing, `rejectImportExpressions` will
|
|
@@ -5723,10 +5792,23 @@ const importPattern= new FERAL_REG_EXP(
|
|
|
5723
5792
|
* apparent import expressions in literal strings or comments.
|
|
5724
5793
|
*
|
|
5725
5794
|
* The current conservative rule looks for the identifier "import"
|
|
5726
|
-
* followed by either an open paren or something that looks like
|
|
5727
|
-
* beginning of a comment.
|
|
5728
|
-
*
|
|
5729
|
-
*
|
|
5795
|
+
* followed by either an open paren, a dot, or something that looks like
|
|
5796
|
+
* the beginning of a comment. The dot case rejects not just a
|
|
5797
|
+
* phase-qualified call such as `import.source(...)` or `import.defer(...)`,
|
|
5798
|
+
* but any property access under `import` at all, including `import.meta`,
|
|
5799
|
+
* regardless of whether the property is then called. This is broader than
|
|
5800
|
+
* strictly necessary: the substring "import." can occur incidentally, for
|
|
5801
|
+
* example in a module path or a comment, and such source text is rejected
|
|
5802
|
+
* too. That tradeoff is intentional: covering every `import.<name>` form,
|
|
5803
|
+
* called or not, without naming specific property names, is judged simpler
|
|
5804
|
+
* and safer than narrowing the match to the shape of a call. We assume that
|
|
5805
|
+
* we do not need to worry about html comment syntax because that was
|
|
5806
|
+
* already rejected by rejectHtmlComments.
|
|
5807
|
+
*
|
|
5808
|
+
* The scan stops short of a trailing run of `//# sourceURL=` or
|
|
5809
|
+
* `//# sourceMappingURL=` comments whose values could not end a comment,
|
|
5810
|
+
* string or template (see `sourceMetaTrailerStart`), so that a module
|
|
5811
|
+
* whose location contains `import.` still loads.
|
|
5730
5812
|
*
|
|
5731
5813
|
* this \s *must* match all kinds of syntax-defined whitespace. If e.g.
|
|
5732
5814
|
* U+2028 (LINE SEPARATOR) or U+2029 (PARAGRAPH SEPARATOR) is treated as
|
|
@@ -5739,7 +5821,8 @@ const importPattern= new FERAL_REG_EXP(
|
|
|
5739
5821
|
* @returns {string}
|
|
5740
5822
|
*/
|
|
5741
5823
|
const rejectImportExpressions= (src)=>{
|
|
5742
|
-
const
|
|
5824
|
+
const scanned= stringSlice(src, 0, sourceMetaTrailerStart(src));
|
|
5825
|
+
const lineNumber= getLineNumber(scanned, importPattern);
|
|
5743
5826
|
if( lineNumber< 0) {
|
|
5744
5827
|
return src;
|
|
5745
5828
|
}
|
package/dist/lockdown.umd.js
CHANGED
|
@@ -5596,7 +5596,8 @@ const getSourceURL= (src)=>{
|
|
|
5596
5596
|
})
|
|
5597
5597
|
,
|
|
5598
5598
|
// === functors[27] ===
|
|
5599
|
-
(({ imports: $h_imports, liveVar: $h_live, onceVar: $h_once, importMeta: $h____meta, }) => { let FERAL_REG_EXP,SyntaxError,stringReplace,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)]],["stringReplace", [$h_a => (stringReplace = $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)]]]]]);
|
|
5599
|
+
(({ imports: $h_imports, liveVar: $h_live, onceVar: $h_once, importMeta: $h____meta, }) => { let FERAL_REG_EXP,SyntaxError,regexpExec,stringReplace,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)]],["stringReplace", [$h_a => (stringReplace = $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)]]]]]);
|
|
5600
|
+
|
|
5600
5601
|
|
|
5601
5602
|
|
|
5602
5603
|
|
|
@@ -5704,10 +5705,78 @@ const evadeHtmlCommentTest= (src)=>{
|
|
|
5704
5705
|
// /////////////////////////////////////////////////////////////////////////////
|
|
5705
5706
|
$h_once.evadeHtmlCommentTest(evadeHtmlCommentTest);
|
|
5706
5707
|
const importPattern= new FERAL_REG_EXP(
|
|
5707
|
-
'(^|[^.]|\\.\\.\\.)\\bimport(\\s*(?:\\(
|
|
5708
|
+
'(^|[^.]|\\.\\.\\.)\\bimport(\\s*(?:\\(|\\.|/[/*]))',
|
|
5708
5709
|
'g');
|
|
5709
5710
|
|
|
5710
5711
|
|
|
5712
|
+
/**
|
|
5713
|
+
* Matches one line of a run of `//# sourceURL=` and `//# sourceMappingURL=`
|
|
5714
|
+
* comments at the very end of the source (`sourceMetaTrailerStart` finds
|
|
5715
|
+
* the run), as module-source, compartment-mapper and
|
|
5716
|
+
* bundlers append to evaluated code (a module's location may well contain
|
|
5717
|
+
* `import.`, as in `conditional-import.js`).
|
|
5718
|
+
*
|
|
5719
|
+
* Each line must begin at a line start and its value must hold no whitespace
|
|
5720
|
+
* and none of `*`, backtick, `$`, quotes or backslash. Such a line is inert
|
|
5721
|
+
* wherever it stands: outside any literal it is a line comment; a regular
|
|
5722
|
+
* expression literal cannot span lines; and inside a block comment, a string
|
|
5723
|
+
* continued from the line before or a template literal, the line can neither
|
|
5724
|
+
* close that context (no `*`, quote or backtick) nor open a substitution (no
|
|
5725
|
+
* `$`). Since nothing but whitespace follows the run, an unclosed context
|
|
5726
|
+
* there is a SyntaxError. So `rejectImportExpressions` need not scan it.
|
|
5727
|
+
*
|
|
5728
|
+
* A `/*# sourceMappingURL=` block comment is not skipped but scanned like
|
|
5729
|
+
* any other code, which can only make the check stricter.
|
|
5730
|
+
*/
|
|
5731
|
+
const sourceMetaLinePattern= new FERAL_REG_EXP(
|
|
5732
|
+
'^//# source(?:Mapping)?URL=[^\\s*`$\'"\\\\]*$');
|
|
5733
|
+
|
|
5734
|
+
|
|
5735
|
+
const whitespacePattern= new FERAL_REG_EXP('^\\s$');
|
|
5736
|
+
|
|
5737
|
+
const lineTerminatorPattern= new FERAL_REG_EXP('^[\\n\\r\\u2028\\u2029]$');
|
|
5738
|
+
|
|
5739
|
+
/**
|
|
5740
|
+
* Returns the index at which the trailing run of source meta comments
|
|
5741
|
+
* begins, at its leading line terminator if it has one, or the length of
|
|
5742
|
+
* the source if there is no such run. It reads the source backward, one
|
|
5743
|
+
* line at a time, and tests each line with `sourceMetaLinePattern` alone,
|
|
5744
|
+
* so it takes time linear in the length of the source. A single regular
|
|
5745
|
+
* expression for the whole run, `(?:(?:^|[\n\r\u2028\u2029])<line>)+\s*$`,
|
|
5746
|
+
* finds the same run, but a search retries it at every line terminator,
|
|
5747
|
+
* which takes time quadratic in the number of lines of the run.
|
|
5748
|
+
*
|
|
5749
|
+
* @param {string} src
|
|
5750
|
+
* @returns {number}
|
|
5751
|
+
*/
|
|
5752
|
+
const sourceMetaTrailerStart= (src)=>{
|
|
5753
|
+
let end= src.length;
|
|
5754
|
+
while( end> 0&& regexpExec(whitespacePattern, src[end- 1])!== null) {
|
|
5755
|
+
end-= 1;
|
|
5756
|
+
}
|
|
5757
|
+
let start= src.length;
|
|
5758
|
+
for(;;) {
|
|
5759
|
+
let lineStart= end;
|
|
5760
|
+
while(
|
|
5761
|
+
lineStart> 0&&
|
|
5762
|
+
regexpExec(lineTerminatorPattern, src[lineStart- 1])=== null)
|
|
5763
|
+
{
|
|
5764
|
+
lineStart-= 1;
|
|
5765
|
+
}
|
|
5766
|
+
if(
|
|
5767
|
+
regexpExec(sourceMetaLinePattern, stringSlice(src, lineStart, end))===
|
|
5768
|
+
null)
|
|
5769
|
+
{
|
|
5770
|
+
return start;
|
|
5771
|
+
}
|
|
5772
|
+
if( lineStart=== 0) {
|
|
5773
|
+
return 0;
|
|
5774
|
+
}
|
|
5775
|
+
start= lineStart- 1;
|
|
5776
|
+
end= lineStart- 1;
|
|
5777
|
+
}
|
|
5778
|
+
};
|
|
5779
|
+
|
|
5711
5780
|
/**
|
|
5712
5781
|
* Conservatively reject the source text if it may contain a dynamic
|
|
5713
5782
|
* import expression. To reject without parsing, `rejectImportExpressions` will
|
|
@@ -5723,10 +5792,23 @@ const importPattern= new FERAL_REG_EXP(
|
|
|
5723
5792
|
* apparent import expressions in literal strings or comments.
|
|
5724
5793
|
*
|
|
5725
5794
|
* The current conservative rule looks for the identifier "import"
|
|
5726
|
-
* followed by either an open paren or something that looks like
|
|
5727
|
-
* beginning of a comment.
|
|
5728
|
-
*
|
|
5729
|
-
*
|
|
5795
|
+
* followed by either an open paren, a dot, or something that looks like
|
|
5796
|
+
* the beginning of a comment. The dot case rejects not just a
|
|
5797
|
+
* phase-qualified call such as `import.source(...)` or `import.defer(...)`,
|
|
5798
|
+
* but any property access under `import` at all, including `import.meta`,
|
|
5799
|
+
* regardless of whether the property is then called. This is broader than
|
|
5800
|
+
* strictly necessary: the substring "import." can occur incidentally, for
|
|
5801
|
+
* example in a module path or a comment, and such source text is rejected
|
|
5802
|
+
* too. That tradeoff is intentional: covering every `import.<name>` form,
|
|
5803
|
+
* called or not, without naming specific property names, is judged simpler
|
|
5804
|
+
* and safer than narrowing the match to the shape of a call. We assume that
|
|
5805
|
+
* we do not need to worry about html comment syntax because that was
|
|
5806
|
+
* already rejected by rejectHtmlComments.
|
|
5807
|
+
*
|
|
5808
|
+
* The scan stops short of a trailing run of `//# sourceURL=` or
|
|
5809
|
+
* `//# sourceMappingURL=` comments whose values could not end a comment,
|
|
5810
|
+
* string or template (see `sourceMetaTrailerStart`), so that a module
|
|
5811
|
+
* whose location contains `import.` still loads.
|
|
5730
5812
|
*
|
|
5731
5813
|
* this \s *must* match all kinds of syntax-defined whitespace. If e.g.
|
|
5732
5814
|
* U+2028 (LINE SEPARATOR) or U+2029 (PARAGRAPH SEPARATOR) is treated as
|
|
@@ -5739,7 +5821,8 @@ const importPattern= new FERAL_REG_EXP(
|
|
|
5739
5821
|
* @returns {string}
|
|
5740
5822
|
*/
|
|
5741
5823
|
const rejectImportExpressions= (src)=>{
|
|
5742
|
-
const
|
|
5824
|
+
const scanned= stringSlice(src, 0, sourceMetaTrailerStart(src));
|
|
5825
|
+
const lineNumber= getLineNumber(scanned, importPattern);
|
|
5743
5826
|
if( lineNumber< 0) {
|
|
5744
5827
|
return src;
|
|
5745
5828
|
}
|