We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents 7434a58 + ed80e4e commit f78ea26Copy full SHA for f78ea26
4 files changed
javascript/extractor/src/com/semmle/jcorn/Parser.java
@@ -244,7 +244,13 @@ public Parser(Options options, String input, int startPos) {
244
this.exprAllowed = true;
245
246
// Figure out if it's a module code.
247
- this.strict = this.inModule = options.sourceType().equals("module");
+ 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;
254
255
// Used to signify the start of a potential arrow function
256
this.potentialArrowAt = -1;
@@ -323,18 +329,13 @@ protected void next() {
323
329
this.nextToken();
324
330
}
325
331
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)).
328
335
336
public void setStrict(boolean strict) {
- this.strict = strict;
- if (this.type != TokenType.num && this.type != TokenType.string) return;
- this.pos = this.start;
- while (this.pos < this.lineStart) {
- this.lineStart = this.input.lastIndexOf("\n", this.lineStart - 2) + 1;
- --this.curLine;
- }
337
- this.nextToken();
+ // always false
338
+ return;
339
340
341
public TokContext curContext() {
@@ -3107,7 +3108,7 @@ protected BlockStatement parseBlock(boolean allowStrict) {
3107
3108
if (stmt != null) body.add(stmt);
3109
if (first && allowStrict && this.isUseStrict(stmt)) {
3110
oldStrict = this.strict;
- this.setStrict(this.strict = true);
3111
+ this.setStrict(true);
3112
3113
first = false;
3114
javascript/extractor/src/com/semmle/js/extractor/Main.java
@@ -41,7 +41,7 @@ public class Main {
41
* A version identifier that should be updated every time the extractor changes in such a way that
42
* it may produce different tuples for the same file under the same {@link ExtractorConfig}.
43
*/
44
- public static final String EXTRACTOR_VERSION = "2023-10-13";
+ public static final String EXTRACTOR_VERSION = "2024-04-17";
45
46
public static final Pattern NEWLINE = Pattern.compile("\n");
47
javascript/extractor/tests/strictmode/output/trap/assignargs.js.trap
@@ -196,29 +196,5 @@ successor(#20045,#20048)
196
successor(#20057,#20041)
197
successor(#20038,#20037)
198
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)
223
numlines(#10000,4,4,0)
224
filetype(#10000,"javascript")
javascript/ql/src/change-notes/2024-04-17-strict-mode.md
@@ -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