Skip to content

Commit f78ea26

Browse files
authored
Merge pull request github#16161 from RasmusWL/js/strict-mode
JS: Parser: Never run in strict mode
2 parents 7434a58 + ed80e4e commit f78ea26

File tree

4 files changed

+21
-37
lines changed

4 files changed

+21
-37
lines changed

javascript/extractor/src/com/semmle/jcorn/Parser.java

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,13 @@ public Parser(Options options, String input, int startPos) {
244244
this.exprAllowed = true;
245245

246246
// Figure out if it's a module code.
247-
this.strict = this.inModule = options.sourceType().equals("module");
247+
this.inModule = options.sourceType().equals("module");
248+
249+
// We don't care to report syntax errors in code that might be using strict mode. In
250+
// the end, we don't know whether that code is put through additional build steps
251+
// causing our alleged syntax errors to disappear. Therefore, we hardcode
252+
// this.strict to false.
253+
this.strict = false;
248254

249255
// Used to signify the start of a potential arrow function
250256
this.potentialArrowAt = -1;
@@ -323,18 +329,13 @@ protected void next() {
323329
this.nextToken();
324330
}
325331

326-
// Toggle strict mode. Re-reads the next number or string to please
327-
// pedantic tests (`"use strict"; 010;` should fail).
332+
// DEPRECATED. When we respected strict mode, this method was used to toggle strict
333+
// mode (and would re-read the next number or string to please pedantic tests (`"use
334+
// strict"; 010;` should fail)).
328335

329336
public void setStrict(boolean strict) {
330-
this.strict = strict;
331-
if (this.type != TokenType.num && this.type != TokenType.string) return;
332-
this.pos = this.start;
333-
while (this.pos < this.lineStart) {
334-
this.lineStart = this.input.lastIndexOf("\n", this.lineStart - 2) + 1;
335-
--this.curLine;
336-
}
337-
this.nextToken();
337+
// always false
338+
return;
338339
}
339340

340341
public TokContext curContext() {
@@ -3107,7 +3108,7 @@ protected BlockStatement parseBlock(boolean allowStrict) {
31073108
if (stmt != null) body.add(stmt);
31083109
if (first && allowStrict && this.isUseStrict(stmt)) {
31093110
oldStrict = this.strict;
3110-
this.setStrict(this.strict = true);
3111+
this.setStrict(true);
31113112
}
31123113
first = false;
31133114
}

javascript/extractor/src/com/semmle/js/extractor/Main.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public class Main {
4141
* A version identifier that should be updated every time the extractor changes in such a way that
4242
* it may produce different tuples for the same file under the same {@link ExtractorConfig}.
4343
*/
44-
public static final String EXTRACTOR_VERSION = "2023-10-13";
44+
public static final String EXTRACTOR_VERSION = "2024-04-17";
4545

4646
public static final Pattern NEWLINE = Pattern.compile("\n");
4747

javascript/extractor/tests/strictmode/output/trap/assignargs.js.trap

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -196,29 +196,5 @@ successor(#20045,#20048)
196196
successor(#20057,#20041)
197197
successor(#20038,#20037)
198198
successor(#20054,#20038)
199-
#20059=*
200-
js_parse_errors(#20059,#20001,"Error: Assigning to arguments in strict mode"," arguments = 42;
201-
")
202-
#20060=@"loc,{#10000},3,3,3,3"
203-
locations_default(#20060,#10000,3,3,3,3)
204-
hasLocation(#20059,#20060)
205-
#20061=*
206-
lines(#20061,#20001,"function f() {","
207-
")
208-
hasLocation(#20061,#20003)
209-
#20062=*
210-
lines(#20062,#20001," 'use strict';","
211-
")
212-
hasLocation(#20062,#20005)
213-
indentation(#10000,2," ",2)
214-
#20063=*
215-
lines(#20063,#20001," arguments = 42;","
216-
")
217-
hasLocation(#20063,#20007)
218-
indentation(#10000,3," ",2)
219-
#20064=*
220-
lines(#20064,#20001,"}","")
221-
hasLocation(#20064,#20009)
222-
numlines(#20001,4,0,0)
223199
numlines(#10000,4,4,0)
224200
filetype(#10000,"javascript")
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* The JavaScript extractor will on longer report syntax errors related to "strict mode".
5+
Files containing such errors are now being fully analyzed along with other sources files.
6+
This improves our support for source files that technically break the "strict mode" rules,
7+
but where a build steps transforms the code such that it ends up working at runtime.

0 commit comments

Comments
 (0)