mirror of
https://github.com/morluto/rea.git
synced 2026-10-28 10:25:42 +00:00
* test(javascript): reproduce TypeScript source dialect loss Add native directory/ASAR and built public CLI owners with actual locked native TypeScript syntax/emit and independent Babel source-range oracles. Production and every workflow remain unchanged. Signed-off-by: Rudy Celekli <rudy@gradiahq.com> * test(javascript): admit isolated native compiler inputs Use the actual TypeScript7 producer-requested --ignoreConfig flag when supplying isolated source filenames. Preserve every graph input, owning assertion, control and production file. Signed-off-by: Rudy Celekli <rudy@gradiahq.com> * fix(javascript): parse plain TypeScript artifacts without JSX Select the plain .ts dialect using the artifact source path so valid angle-bracket assertions retain syntax-derived graph facts. Preserve existing JSX defaults and all other dialects. Document the inert artifact parser contract. Signed-off-by: Rudy Celekli <rudy@gradiahq.com> --------- Signed-off-by: Rudy Celekli <rudy@gradiahq.com>
33 lines
1.2 KiB
TypeScript
33 lines
1.2 KiB
TypeScript
import { parse } from "@babel/parser";
|
|
|
|
/** Babel AST produced by REA's inert JavaScript parser boundary. */
|
|
export type ParsedJavaScriptSource = ReturnType<typeof parse>;
|
|
|
|
/** Parse JavaScript or TypeScript once without attaching comments to AST nodes. */
|
|
export const parseJavaScriptSource = (
|
|
source: string,
|
|
sourcePath?: string,
|
|
): ParsedJavaScriptSource | null => {
|
|
try {
|
|
return parse(source, {
|
|
sourceType: "unambiguous",
|
|
errorRecovery: true,
|
|
attachComment: false,
|
|
// "decorators-legacy" admits both the standard and the legacy decorator
|
|
// forms, including parameter decorators. Without it a decorated
|
|
// TypeScript source fails to parse at all rather than reporting
|
|
// recovered syntax, which loses every fact derived from that source.
|
|
// Plain .ts artifacts admit angle-bracket type assertions instead of JSX.
|
|
// Unknown paths retain the existing JSX-capable parser contract.
|
|
plugins:
|
|
sourcePath?.toLowerCase().endsWith(".ts") === true
|
|
? ["decorators-legacy", "typescript"]
|
|
: ["decorators-legacy", "jsx", "typescript"],
|
|
});
|
|
} catch (cause: unknown) {
|
|
// Unparseable source is represented by the null return.
|
|
void cause;
|
|
return null;
|
|
}
|
|
};
|