refactor(compiler): make OutputAst
contain the moduleName, not the filePath (#16832).
The goal of this change is to simplify the emitters, as we will soon create a new one to emit TypeScript nodes directly.
This commit is contained in:

committed by
Chuck Jazdzewski

parent
3b28c75d1f
commit
6123b9c0c6
@ -9,7 +9,6 @@
|
||||
import {ParseLocation, ParseSourceFile} from '@angular/compiler';
|
||||
import {StaticSymbol} from '@angular/compiler/src/aot/static_symbol';
|
||||
import * as o from '@angular/compiler/src/output/output_ast';
|
||||
import {ImportResolver} from '@angular/compiler/src/output/path_util';
|
||||
import {SourceMap} from '@angular/compiler/src/output/source_map';
|
||||
import {TypeScriptEmitter} from '@angular/compiler/src/output/ts_emitter';
|
||||
import {ParseSourceSpan} from '@angular/compiler/src/parse_util';
|
||||
@ -19,36 +18,23 @@ import {extractSourceMap, originalPositionFor} from './source_map_util';
|
||||
const someGenFilePath = 'somePackage/someGenFile';
|
||||
const someSourceFilePath = 'somePackage/someSourceFile';
|
||||
|
||||
class SimpleJsImportGenerator implements ImportResolver {
|
||||
fileNameToModuleName(importedUrlStr: string, moduleUrlStr: string): string {
|
||||
return importedUrlStr;
|
||||
}
|
||||
getImportAs(symbol: StaticSymbol): StaticSymbol|null { return null; }
|
||||
getTypeArity(symbol: StaticSymbol): number|null { return null; }
|
||||
}
|
||||
|
||||
export function main() {
|
||||
// Not supported features of our OutputAst in TS:
|
||||
// - real `const` like in Dart
|
||||
// - final fields
|
||||
|
||||
describe('TypeScriptEmitter', () => {
|
||||
let importResolver: ImportResolver;
|
||||
let emitter: TypeScriptEmitter;
|
||||
let someVar: o.ReadVarExpr;
|
||||
|
||||
beforeEach(() => {
|
||||
importResolver = new SimpleJsImportGenerator();
|
||||
emitter = new TypeScriptEmitter(importResolver);
|
||||
emitter = new TypeScriptEmitter();
|
||||
someVar = o.variable('someVar');
|
||||
});
|
||||
|
||||
function emitSourceMap(
|
||||
stmt: o.Statement | o.Statement[], exportedVars: string[] | null = null,
|
||||
preamble?: string): SourceMap {
|
||||
function emitSourceMap(stmt: o.Statement | o.Statement[], preamble?: string): SourceMap {
|
||||
const stmts = Array.isArray(stmt) ? stmt : [stmt];
|
||||
const source = emitter.emitStatements(
|
||||
someSourceFilePath, someGenFilePath, stmts, exportedVars || [], preamble);
|
||||
const source = emitter.emitStatements(someSourceFilePath, someGenFilePath, stmts, preamble);
|
||||
return extractSourceMap(source) !;
|
||||
}
|
||||
|
||||
@ -59,7 +45,7 @@ export function main() {
|
||||
const endLocation = new ParseLocation(source, 7, 0, 6);
|
||||
const sourceSpan = new ParseSourceSpan(startLocation, endLocation);
|
||||
const someVar = o.variable('someVar', null, sourceSpan);
|
||||
const sm = emitSourceMap(someVar.toStmt(), [], '/* MyPreamble \n */');
|
||||
const sm = emitSourceMap(someVar.toStmt(), '/* MyPreamble \n */');
|
||||
|
||||
expect(sm.sources).toEqual([someSourceFilePath, 'in.js']);
|
||||
expect(sm.sourcesContent).toEqual([' ', ';;;var']);
|
||||
|
Reference in New Issue
Block a user