mirror of
https://github.com/morluto/rea.git
synced 2026-10-29 19:05:45 +00:00
refactor(javascript): group domain semantics and contracts (#907)
This commit is contained in:
1 parent
d5f28fb29c
commit
f6a58f1062
253 files changed
+432
-410
No files matched your search
@@ -0,0 +1,65 @@
|
||||
import { parse } from "@babel/parser";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { analyzeJavaScriptStaticSource } from "./javascriptStaticAnalysis.js";
|
||||
|
||||
const directive = "//# sourceMappingURL=app.js.map";
|
||||
|
||||
describe("source map directive coordinates", () => {
|
||||
it.each([
|
||||
["LF", "\n"],
|
||||
["CRLF", "\r\n"],
|
||||
["CR", "\r"],
|
||||
["line separator", "\u2028"],
|
||||
["paragraph separator", "\u2029"],
|
||||
["same-line UTF-16 columns", " "],
|
||||
["vertical tab whitespace", "\v"],
|
||||
["form feed whitespace", "\f"],
|
||||
["mixed terminators", "\r\n\r\u2028\n\u2029"],
|
||||
])("agrees with Babel after %s", (_name, separator) => {
|
||||
const source = `const marker = "😀";${separator} ${directive}`;
|
||||
const location = parse(source).comments?.[0]?.loc;
|
||||
if (location === undefined)
|
||||
throw new Error("Expected the directive comment location");
|
||||
const { start, end } = location;
|
||||
|
||||
const result = analyzeJavaScriptStaticSource(source);
|
||||
expect(result.parse_status).toBe("complete");
|
||||
expect(result.source_map_urls).toEqual([
|
||||
{
|
||||
declared_url: "app.js.map",
|
||||
location: {
|
||||
start: { line: start.line, column: start.column },
|
||||
end: { line: end.line, column: end.column },
|
||||
},
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it("counts terminators inside a block directive without including its closer", () => {
|
||||
const source =
|
||||
"const value = 1;\r/*#\u2028 sourceMappingURL=\r\n app.js.map */";
|
||||
expect(analyzeJavaScriptStaticSource(source).source_map_urls).toEqual([
|
||||
{
|
||||
declared_url: "app.js.map",
|
||||
location: {
|
||||
start: { line: 2, column: 0 },
|
||||
end: { line: 4, column: " app.js.map".length },
|
||||
},
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it("preserves the first location when a URL is repeated across terminators", () => {
|
||||
const source = `const marker = "😀";\r ${directive}\u2028${directive}`;
|
||||
expect(analyzeJavaScriptStaticSource(source).source_map_urls).toEqual([
|
||||
{
|
||||
declared_url: "app.js.map",
|
||||
location: {
|
||||
start: { line: 2, column: 2 },
|
||||
end: { line: 2, column: directive.length + 2 },
|
||||
},
|
||||
},
|
||||
]);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user