2017-01-27 17:23:12 -05:00
|
|
|
/**
|
|
|
|
* @license
|
|
|
|
* Copyright Google Inc. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
|
|
* found in the LICENSE file at https://angular.io/license
|
|
|
|
*/
|
|
|
|
|
|
|
|
import {StaticSymbol} from '@angular/compiler/src/aot/static_symbol';
|
|
|
|
import {CompileIdentifierMetadata} from '@angular/compiler/src/compile_metadata';
|
|
|
|
import {JavaScriptEmitter} from '@angular/compiler/src/output/js_emitter';
|
|
|
|
import * as o from '@angular/compiler/src/output/output_ast';
|
|
|
|
import {SourceMap} from '@angular/compiler/src/output/source_map';
|
|
|
|
import {ParseLocation, ParseSourceFile, ParseSourceSpan} from '@angular/compiler/src/parse_util';
|
|
|
|
|
2017-12-16 14:35:47 -05:00
|
|
|
import {extractSourceMap, originalPositionFor} from '@angular/compiler/testing/src/output/source_map_util';
|
2017-01-27 17:23:12 -05:00
|
|
|
|
2017-03-15 18:50:30 -04:00
|
|
|
const someGenFilePath = 'somePackage/someGenFile';
|
2017-01-27 17:23:12 -05:00
|
|
|
|
2017-12-16 17:42:55 -05:00
|
|
|
{
|
2017-01-27 17:23:12 -05:00
|
|
|
describe('JavaScriptEmitter', () => {
|
|
|
|
let emitter: JavaScriptEmitter;
|
|
|
|
let someVar: o.ReadVarExpr;
|
|
|
|
|
2020-04-08 13:14:18 -04:00
|
|
|
beforeEach(() => {
|
|
|
|
emitter = new JavaScriptEmitter();
|
|
|
|
});
|
2017-01-27 17:23:12 -05:00
|
|
|
|
2020-04-08 13:14:18 -04:00
|
|
|
function emitSourceMap(stmt: o.Statement|o.Statement[], preamble?: string): SourceMap {
|
2017-01-27 17:23:12 -05:00
|
|
|
const stmts = Array.isArray(stmt) ? stmt : [stmt];
|
2017-10-04 16:37:27 -04:00
|
|
|
const source = emitter.emitStatements(someGenFilePath, stmts, preamble);
|
2020-04-08 13:14:18 -04:00
|
|
|
return extractSourceMap(source)!;
|
2017-01-27 17:23:12 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
describe('source maps', () => {
|
|
|
|
it('should emit an inline source map', () => {
|
|
|
|
const source = new ParseSourceFile(';;;var', 'in.js');
|
|
|
|
const startLocation = new ParseLocation(source, 0, 0, 3);
|
|
|
|
const endLocation = new ParseLocation(source, 7, 0, 6);
|
|
|
|
const sourceSpan = new ParseSourceSpan(startLocation, endLocation);
|
|
|
|
const someVar = o.variable('someVar', null, sourceSpan);
|
2017-05-16 19:30:37 -04:00
|
|
|
const sm = emitSourceMap(someVar.toStmt(), '/* MyPreamble \n */');
|
2017-01-27 17:23:12 -05:00
|
|
|
|
2017-10-04 16:37:27 -04:00
|
|
|
expect(sm.sources).toEqual([someGenFilePath, 'in.js']);
|
2017-03-17 12:44:27 -04:00
|
|
|
expect(sm.sourcesContent).toEqual([' ', ';;;var']);
|
2017-03-15 18:50:30 -04:00
|
|
|
expect(originalPositionFor(sm, {line: 3, column: 0}))
|
2017-03-14 12:16:15 -04:00
|
|
|
.toEqual({line: 1, column: 3, source: 'in.js'});
|
2017-01-27 17:23:12 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|