MCPcopy Create free account
hub / github.com/angular/angular / compileTsToJs

Function compileTsToJs

packages/compiler-cli/preprocessor/test/compliance_spec.ts:104–136  ·  view source on GitHub ↗
(tsContent: string, target?: string)

Source from the content-addressed store, hash-verified

102}
103
104async function compileTsToJs(tsContent: string, target?: string): Promise<string> {
105 // Honor the test case's `target` so ES5 fixtures get downleveled (tagged templates ->
106 // `__makeTemplateObject`, classes -> functions), matching ngtsc's compliance goldens.
107 const scriptTarget =
108 (target
109 ? (ts.ScriptTarget as unknown as Record<string, ts.ScriptTarget>)[target.toUpperCase()]
110 : undefined) ?? ts.ScriptTarget.ES2022;
111
112 const result = ts.transpileModule(tsContent, {
113 compilerOptions: {
114 target: scriptTarget,
115 module: ts.ModuleKind.ES2015,
116 experimentalDecorators: true,
117 emitDecoratorMetadata: true,
118 removeComments: false,
119 },
120 });
121
122 const outputText = result.outputText.replace(/\r\n/g, '\n').replace(/\/virtual_project\//g, '/');
123
124 try {
125 return await prettier.format(outputText, {
126 parser: 'babel',
127 printWidth: 100,
128 singleQuote: false,
129 trailingComma: 'none',
130 arrowParens: 'avoid',
131 quoteProps: 'preserve',
132 });
133 } catch {
134 return outputText;
135 }
136}
137
138const LOCAL_EXTRA_CHECK_FUNCTIONS: Record<string, (generated: string, ...args: any[]) => boolean> =
139 {

Callers 1

compliance_spec.tsFile · 0.85

Calls 2

replaceMethod · 0.45
formatMethod · 0.45

Tested by

no test coverage detected