mirror of
https://github.com/morluto/rea.git
synced 2026-11-05 22:36:08 +00:00
fix(javascript): derive program strictness from parser context
This commit is contained in:
1 parent
7f3e32c69b
commit
002f9df43a
4 files changed
+43
-13
No files matched your search
@@ -6,6 +6,7 @@ import {
|
||||
parseRecoveredJavaScript,
|
||||
parserPluginsForPath,
|
||||
javaScriptRuntimeContext,
|
||||
javaScriptProgramStrictness,
|
||||
} from "./javascriptSourceParser.js";
|
||||
import { analyzeParsedJavaScriptStaticSource } from "./javascriptStaticAnalysis.js";
|
||||
|
||||
@@ -48,6 +49,25 @@ it.each([
|
||||
},
|
||||
);
|
||||
|
||||
it.each([
|
||||
["const args=[]; export = args;", "fixture.ts", "sloppy"],
|
||||
['"use strict"; const args=[]; export = args;', "fixture.ts", "strict"],
|
||||
['import type {T} from "example";', "fixture.ts", "unknown"],
|
||||
["const args=[];", "fixture.mjs", "strict"],
|
||||
["const args=[];", "fixture.cjs", "sloppy"],
|
||||
] as const)(
|
||||
"owns program strictness independently of parser syntax: %s (%s)",
|
||||
(source, path, strictness) => {
|
||||
const parsed = parseJavaScriptSource(source, path);
|
||||
if (parsed === null) throw new Error("Expected parsed source");
|
||||
expect(javaScriptProgramStrictness(parsed.program)).toBe(strictness);
|
||||
const recovered = parseRecoveredJavaScript(source, path, {
|
||||
plugins: parserPluginsForPath(path),
|
||||
}).file;
|
||||
expect(javaScriptProgramStrictness(recovered.program)).toBe(strictness);
|
||||
},
|
||||
);
|
||||
|
||||
const analyze = (source: string, path: string) => {
|
||||
const parsed = parseJavaScriptSource(source, path);
|
||||
return parsed === null
|
||||
|
||||
Reference in new issue
Block a user