2019-02-08 17:10:21 -05:00
|
|
|
/**
|
|
|
|
* @license
|
2020-05-19 15:08:49 -04:00
|
|
|
* Copyright Google LLC All Rights Reserved.
|
2019-02-08 17:10:21 -05:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2019-06-06 15:22:32 -04:00
|
|
|
/// <reference types="node" />
|
2019-02-08 17:10:21 -05:00
|
|
|
import {inspect} from 'util';
|
|
|
|
|
2019-06-06 15:22:32 -04:00
|
|
|
import {runInEachFileSystem} from '../../src/ngtsc/file_system/testing';
|
2020-11-04 15:27:19 -05:00
|
|
|
import {loadStandardTestFiles} from '../../src/ngtsc/testing';
|
2019-02-08 17:10:21 -05:00
|
|
|
import {tsSourceMapBug29300Fixed} from '../../src/ngtsc/util/src/ts_source_map_bug_29300';
|
|
|
|
|
|
|
|
import {NgtscTestEnvironment} from './env';
|
2020-04-07 15:43:43 -04:00
|
|
|
import {getMappedSegments, SegmentMapping} from './sourcemap_utils';
|
2019-02-08 17:10:21 -05:00
|
|
|
|
2019-06-06 15:22:32 -04:00
|
|
|
const testFiles = loadStandardTestFiles();
|
2019-02-08 17:10:21 -05:00
|
|
|
|
2019-06-06 15:22:32 -04:00
|
|
|
runInEachFileSystem((os) => {
|
|
|
|
describe('template source-mapping', () => {
|
2020-04-07 15:43:43 -04:00
|
|
|
let env!: NgtscTestEnvironment;
|
2019-02-08 17:10:21 -05:00
|
|
|
|
2019-06-06 15:22:32 -04:00
|
|
|
beforeEach(() => {
|
|
|
|
env = NgtscTestEnvironment.setup(testFiles);
|
2020-08-31 11:27:44 -04:00
|
|
|
env.tsconfig({sourceMap: true, target: 'es2015', enableI18nLegacyMessageIdFormat: false});
|
2019-02-08 17:10:21 -05:00
|
|
|
});
|
|
|
|
|
2019-06-06 15:22:32 -04:00
|
|
|
describe('Inline templates', () => {
|
|
|
|
describe('(element creation)', () => {
|
|
|
|
it('should map simple element with content', () => {
|
|
|
|
const mappings = compileAndMap('<h1>Heading 1</h1>');
|
2020-11-19 07:21:01 -05:00
|
|
|
expectMapping(
|
|
|
|
mappings,
|
2019-06-06 15:22:32 -04:00
|
|
|
{source: '<h1>', generated: 'i0.ɵɵelementStart(0, "h1")', sourceUrl: '../test.ts'});
|
2020-11-19 07:21:01 -05:00
|
|
|
expectMapping(mappings, {
|
2019-06-06 15:22:32 -04:00
|
|
|
source: 'Heading 1',
|
|
|
|
generated: 'i0.ɵɵtext(1, "Heading 1")',
|
|
|
|
sourceUrl: '../test.ts'
|
|
|
|
});
|
2020-11-19 07:21:01 -05:00
|
|
|
expectMapping(
|
|
|
|
mappings, {source: '</h1>', generated: 'i0.ɵɵelementEnd()', sourceUrl: '../test.ts'});
|
2019-06-06 15:22:32 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should map void element', () => {
|
|
|
|
const mappings = compileAndMap('<hr>');
|
2020-11-19 07:21:01 -05:00
|
|
|
expectMapping(
|
|
|
|
mappings,
|
2019-06-06 15:22:32 -04:00
|
|
|
{source: '<hr>', generated: 'i0.ɵɵelement(0, "hr")', sourceUrl: '../test.ts'});
|
2019-02-08 17:10:21 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-06-06 15:22:32 -04:00
|
|
|
describe('(interpolations)', () => {
|
|
|
|
it('should map a mix of interpolated and static content', () => {
|
|
|
|
const mappings = compileAndMap('<h3>Hello {{ name }}</h3>');
|
2020-11-19 07:21:01 -05:00
|
|
|
expectMapping(
|
|
|
|
mappings,
|
2019-06-06 15:22:32 -04:00
|
|
|
{source: '<h3>', generated: 'i0.ɵɵelementStart(0, "h3")', sourceUrl: '../test.ts'});
|
2020-11-19 07:21:01 -05:00
|
|
|
expectMapping(mappings, {
|
2019-06-06 15:22:32 -04:00
|
|
|
source: 'Hello {{ name }}',
|
|
|
|
generated: 'i0.ɵɵtextInterpolate1("Hello ", ctx.name, "")',
|
|
|
|
sourceUrl: '../test.ts'
|
|
|
|
});
|
2020-11-19 07:21:01 -05:00
|
|
|
expectMapping(
|
|
|
|
mappings, {source: '</h3>', generated: 'i0.ɵɵelementEnd()', sourceUrl: '../test.ts'});
|
2019-06-06 15:22:32 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should map a complex interpolated expression', () => {
|
|
|
|
const mappings = compileAndMap('<h2>{{ greeting + " " + name }}</h2>');
|
2020-11-19 07:21:01 -05:00
|
|
|
expectMapping(
|
|
|
|
mappings,
|
2019-06-06 15:22:32 -04:00
|
|
|
{source: '<h2>', generated: 'i0.ɵɵelementStart(0, "h2")', sourceUrl: '../test.ts'});
|
2020-11-19 07:21:01 -05:00
|
|
|
expectMapping(mappings, {
|
2019-06-06 15:22:32 -04:00
|
|
|
source: '{{ greeting + " " + name }}',
|
|
|
|
generated: 'i0.ɵɵtextInterpolate(ctx.greeting + " " + ctx.name)',
|
|
|
|
sourceUrl: '../test.ts'
|
|
|
|
});
|
2020-11-19 07:21:01 -05:00
|
|
|
expectMapping(
|
|
|
|
mappings, {source: '</h2>', generated: 'i0.ɵɵelementEnd()', sourceUrl: '../test.ts'});
|
2019-06-06 15:22:32 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should map interpolated properties', () => {
|
|
|
|
const mappings = compileAndMap('<div id="{{name}}"></div>');
|
2020-11-19 07:21:01 -05:00
|
|
|
expectMapping(mappings, {
|
2019-06-06 15:22:32 -04:00
|
|
|
source: '<div id="{{name}}"></div>',
|
2019-09-23 14:08:51 -04:00
|
|
|
generated: 'i0.ɵɵelement(0, "div", 0)',
|
2019-06-06 15:22:32 -04:00
|
|
|
sourceUrl: '../test.ts'
|
|
|
|
});
|
2020-11-19 07:21:01 -05:00
|
|
|
expectMapping(mappings, {
|
2019-06-06 15:22:32 -04:00
|
|
|
source: 'id="{{name}}"',
|
|
|
|
generated: 'i0.ɵɵpropertyInterpolate("id", ctx.name)',
|
|
|
|
sourceUrl: '../test.ts'
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should map interpolation with pipe', () => {
|
|
|
|
const mappings = compileAndMap('<div>{{200.3 | percent : 2 }}</div>');
|
2020-11-19 07:21:01 -05:00
|
|
|
expectMapping(
|
|
|
|
mappings,
|
2019-06-06 15:22:32 -04:00
|
|
|
{source: '<div>', generated: 'i0.ɵɵelementStart(0, "div")', sourceUrl: '../test.ts'});
|
2020-11-19 07:21:01 -05:00
|
|
|
expectMapping(mappings, {
|
2019-06-06 15:22:32 -04:00
|
|
|
source: '{{200.3 | percent : 2 }}',
|
|
|
|
generated: 'i0.ɵɵtextInterpolate(i0.ɵɵpipeBind2(2, 1, 200.3, 2))',
|
|
|
|
sourceUrl: '../test.ts'
|
|
|
|
});
|
2020-11-19 07:21:01 -05:00
|
|
|
expectMapping(
|
|
|
|
mappings,
|
2019-06-06 15:22:32 -04:00
|
|
|
{source: '</div>', generated: 'i0.ɵɵelementEnd()', sourceUrl: '../test.ts'});
|
2019-02-08 17:10:21 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-06-06 15:22:32 -04:00
|
|
|
describe('(property bindings)', () => {
|
|
|
|
it('should map a simple input binding expression', () => {
|
|
|
|
const mappings = compileAndMap('<div [attr]="name"></div>');
|
2020-11-19 07:21:01 -05:00
|
|
|
expectMapping(mappings, {
|
2019-06-06 15:22:32 -04:00
|
|
|
source: '<div [attr]="name"></div>',
|
2019-09-23 14:08:51 -04:00
|
|
|
generated: 'i0.ɵɵelement(0, "div", 0)',
|
2019-06-06 15:22:32 -04:00
|
|
|
sourceUrl: '../test.ts'
|
|
|
|
});
|
2020-11-19 07:21:01 -05:00
|
|
|
expectMapping(mappings, {
|
2019-06-06 15:22:32 -04:00
|
|
|
source: '[attr]="name"',
|
|
|
|
generated: 'i0.ɵɵproperty("attr", ctx.name)',
|
|
|
|
sourceUrl: '../test.ts'
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should map a complex input binding expression', () => {
|
|
|
|
const mappings = compileAndMap('<div [attr]="greeting + name"></div>');
|
|
|
|
|
2020-11-19 07:21:01 -05:00
|
|
|
expectMapping(mappings, {
|
2019-06-06 15:22:32 -04:00
|
|
|
source: '<div [attr]="greeting + name"></div>',
|
2019-09-23 14:08:51 -04:00
|
|
|
generated: 'i0.ɵɵelement(0, "div", 0)',
|
2019-06-06 15:22:32 -04:00
|
|
|
sourceUrl: '../test.ts'
|
|
|
|
});
|
2020-11-19 07:21:01 -05:00
|
|
|
expectMapping(mappings, {
|
2019-06-06 15:22:32 -04:00
|
|
|
source: '[attr]="greeting + name"',
|
|
|
|
generated: 'i0.ɵɵproperty("attr", ctx.greeting + ctx.name)',
|
|
|
|
sourceUrl: '../test.ts'
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should map a longhand input binding expression', () => {
|
|
|
|
const mappings = compileAndMap('<div bind-attr="name"></div>');
|
2020-11-19 07:21:01 -05:00
|
|
|
expectMapping(mappings, {
|
2019-06-06 15:22:32 -04:00
|
|
|
source: '<div bind-attr="name"></div>',
|
2019-09-23 14:08:51 -04:00
|
|
|
generated: 'i0.ɵɵelement(0, "div", 0)',
|
2019-06-06 15:22:32 -04:00
|
|
|
sourceUrl: '../test.ts'
|
|
|
|
});
|
2020-11-19 07:21:01 -05:00
|
|
|
expectMapping(mappings, {
|
2019-06-06 15:22:32 -04:00
|
|
|
source: 'bind-attr="name"',
|
|
|
|
generated: 'i0.ɵɵproperty("attr", ctx.name)',
|
|
|
|
sourceUrl: '../test.ts'
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should map a simple output binding expression', () => {
|
|
|
|
const mappings = compileAndMap('<button (click)="doSomething()">Do it</button>');
|
2020-11-19 07:21:01 -05:00
|
|
|
expectMapping(mappings, {
|
2019-06-06 15:22:32 -04:00
|
|
|
source: '<button (click)="doSomething()">',
|
2019-09-23 14:08:51 -04:00
|
|
|
generated: 'i0.ɵɵelementStart(0, "button", 0)',
|
2019-06-06 15:22:32 -04:00
|
|
|
sourceUrl: '../test.ts'
|
|
|
|
});
|
2020-11-19 07:21:01 -05:00
|
|
|
expectMapping(
|
|
|
|
mappings,
|
2019-06-06 15:22:32 -04:00
|
|
|
{source: 'Do it', generated: 'i0.ɵɵtext(1, "Do it")', sourceUrl: '../test.ts'});
|
2020-11-19 07:21:01 -05:00
|
|
|
expectMapping(
|
|
|
|
mappings,
|
2019-06-06 15:22:32 -04:00
|
|
|
{source: 'doSomething()', generated: 'ctx.doSomething()', sourceUrl: '../test.ts'});
|
2020-11-19 07:21:01 -05:00
|
|
|
expectMapping(
|
|
|
|
mappings,
|
2019-06-06 15:22:32 -04:00
|
|
|
{source: '</button>', generated: 'i0.ɵɵelementEnd()', sourceUrl: '../test.ts'});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should map a complex output binding expression', () => {
|
|
|
|
const mappings = compileAndMap(
|
|
|
|
`<button (click)="items.push('item' + items.length)">Add Item</button>`);
|
2020-11-19 07:21:01 -05:00
|
|
|
expectMapping(mappings, {
|
2019-06-06 15:22:32 -04:00
|
|
|
source: `<button (click)="items.push('item' + items.length)">`,
|
2019-09-23 14:08:51 -04:00
|
|
|
generated: 'i0.ɵɵelementStart(0, "button", 0)',
|
2019-06-06 15:22:32 -04:00
|
|
|
sourceUrl: '../test.ts'
|
|
|
|
});
|
2020-11-19 07:21:01 -05:00
|
|
|
expectMapping(
|
|
|
|
mappings,
|
2019-06-06 15:22:32 -04:00
|
|
|
{source: 'Add Item', generated: 'i0.ɵɵtext(1, "Add Item")', sourceUrl: '../test.ts'});
|
2020-11-19 07:21:01 -05:00
|
|
|
expectMapping(
|
|
|
|
mappings,
|
2019-06-06 15:22:32 -04:00
|
|
|
{source: 'items.push(', generated: 'ctx.items.push(', sourceUrl: '../test.ts'});
|
2020-11-19 07:21:01 -05:00
|
|
|
expectMapping(mappings, {source: `'item'`, generated: `"item"`, sourceUrl: '../test.ts'});
|
|
|
|
expectMapping(mappings, {
|
2019-12-18 20:30:56 -05:00
|
|
|
source: ' + items.length)',
|
2019-06-06 15:22:32 -04:00
|
|
|
generated: ' + ctx.items.length)',
|
|
|
|
sourceUrl: '../test.ts'
|
|
|
|
});
|
2020-11-19 07:21:01 -05:00
|
|
|
expectMapping(
|
|
|
|
mappings,
|
2019-06-06 15:22:32 -04:00
|
|
|
{source: '</button>', generated: 'i0.ɵɵelementEnd()', sourceUrl: '../test.ts'});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should map a longhand output binding expression', () => {
|
|
|
|
const mappings = compileAndMap('<button on-click="doSomething()">Do it</button>');
|
2020-11-19 07:21:01 -05:00
|
|
|
expectMapping(mappings, {
|
2019-06-06 15:22:32 -04:00
|
|
|
source: '<button on-click="doSomething()">',
|
2019-09-23 14:08:51 -04:00
|
|
|
generated: 'i0.ɵɵelementStart(0, "button", 0)',
|
2019-06-06 15:22:32 -04:00
|
|
|
sourceUrl: '../test.ts'
|
|
|
|
});
|
2020-11-19 07:21:01 -05:00
|
|
|
expectMapping(
|
|
|
|
mappings,
|
2019-06-06 15:22:32 -04:00
|
|
|
{source: 'Do it', generated: 'i0.ɵɵtext(1, "Do it")', sourceUrl: '../test.ts'});
|
2020-11-19 07:21:01 -05:00
|
|
|
expectMapping(
|
|
|
|
mappings,
|
2019-06-06 15:22:32 -04:00
|
|
|
{source: 'doSomething()', generated: 'ctx.doSomething()', sourceUrl: '../test.ts'});
|
2020-11-19 07:21:01 -05:00
|
|
|
expectMapping(
|
|
|
|
mappings,
|
2019-06-06 15:22:32 -04:00
|
|
|
{source: '</button>', generated: 'i0.ɵɵelementEnd()', sourceUrl: '../test.ts'});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should map a two-way binding expression', () => {
|
|
|
|
const mappings = compileAndMap('Name: <input [(ngModel)]="name">');
|
2020-11-19 07:21:01 -05:00
|
|
|
expectMapping(mappings, {
|
2019-06-06 15:22:32 -04:00
|
|
|
source: '<input [(ngModel)]="name">',
|
2019-09-23 14:08:51 -04:00
|
|
|
generated: 'i0.ɵɵelementStart(1, "input", 0)',
|
2019-06-06 15:22:32 -04:00
|
|
|
sourceUrl: '../test.ts'
|
|
|
|
});
|
|
|
|
// TODO: improve mappings here
|
2020-11-19 07:21:01 -05:00
|
|
|
expectMapping(mappings, {
|
2019-06-06 15:22:32 -04:00
|
|
|
source: '[(ngModel)]="name"',
|
|
|
|
generated:
|
|
|
|
'i0.ɵɵlistener("ngModelChange", function TestCmp_Template_input_ngModelChange_1_listener($event) { return ctx.name = $event; })',
|
|
|
|
sourceUrl: '../test.ts'
|
|
|
|
});
|
2020-11-19 07:21:01 -05:00
|
|
|
expectMapping(mappings, {
|
2019-06-06 15:22:32 -04:00
|
|
|
source: '<input [(ngModel)]="name">',
|
|
|
|
generated: 'i0.ɵɵelementEnd()',
|
|
|
|
sourceUrl: '../test.ts'
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should map a longhand two-way binding expression', () => {
|
|
|
|
const mappings = compileAndMap('Name: <input bindon-ngModel="name">');
|
2020-11-19 07:21:01 -05:00
|
|
|
expectMapping(mappings, {
|
2019-06-06 15:22:32 -04:00
|
|
|
source: '<input bindon-ngModel="name">',
|
2019-09-23 14:08:51 -04:00
|
|
|
generated: 'i0.ɵɵelementStart(1, "input", 0)',
|
2019-06-06 15:22:32 -04:00
|
|
|
sourceUrl: '../test.ts'
|
|
|
|
});
|
|
|
|
// TODO: improve mappings here
|
2020-11-19 07:21:01 -05:00
|
|
|
expectMapping(mappings, {
|
2019-06-06 15:22:32 -04:00
|
|
|
source: 'bindon-ngModel="name"',
|
|
|
|
generated:
|
|
|
|
'i0.ɵɵlistener("ngModelChange", function TestCmp_Template_input_ngModelChange_1_listener($event) { return ctx.name = $event; })',
|
|
|
|
sourceUrl: '../test.ts'
|
|
|
|
});
|
2020-11-19 07:21:01 -05:00
|
|
|
expectMapping(mappings, {
|
2019-06-06 15:22:32 -04:00
|
|
|
source: '<input bindon-ngModel="name">',
|
|
|
|
generated: 'i0.ɵɵelementEnd()',
|
|
|
|
sourceUrl: '../test.ts'
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should map a class input binding', () => {
|
|
|
|
const mappings = compileAndMap('<div [class.initial]="isInitial">Message</div>');
|
2020-11-19 07:21:01 -05:00
|
|
|
expectMapping(mappings, {
|
2019-06-06 15:22:32 -04:00
|
|
|
source: '<div [class.initial]="isInitial">',
|
|
|
|
generated: 'i0.ɵɵelementStart(0, "div")',
|
|
|
|
sourceUrl: '../test.ts'
|
|
|
|
});
|
|
|
|
|
|
|
|
// TODO: Add better mappings for binding
|
|
|
|
|
2020-11-19 07:21:01 -05:00
|
|
|
expectMapping(
|
|
|
|
mappings,
|
2019-06-06 15:22:32 -04:00
|
|
|
{source: 'Message', generated: 'i0.ɵɵtext(1, "Message")', sourceUrl: '../test.ts'});
|
|
|
|
|
2020-11-19 07:21:01 -05:00
|
|
|
expectMapping(
|
|
|
|
mappings,
|
2019-06-06 15:22:32 -04:00
|
|
|
{source: '</div>', generated: 'i0.ɵɵelementEnd()', sourceUrl: '../test.ts'});
|
2019-02-08 17:10:21 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-06-06 15:22:32 -04:00
|
|
|
describe('(structural directives)', () => {
|
|
|
|
it('should map *ngIf scenario', () => {
|
|
|
|
const mappings = compileAndMap('<div *ngIf="showMessage()">{{ name }}</div>');
|
2019-02-08 17:10:21 -05:00
|
|
|
|
2020-11-19 07:21:01 -05:00
|
|
|
expectMapping(mappings, {
|
2019-06-06 15:22:32 -04:00
|
|
|
source: '<div *ngIf="showMessage()">',
|
|
|
|
generated: 'i0.ɵɵelementStart(0, "div")',
|
|
|
|
sourceUrl: '../test.ts'
|
|
|
|
});
|
2019-02-08 17:10:21 -05:00
|
|
|
|
2019-06-06 15:22:32 -04:00
|
|
|
// TODO - map the bindings better
|
2019-04-16 20:17:12 -04:00
|
|
|
|
2020-11-19 07:21:01 -05:00
|
|
|
expectMapping(
|
|
|
|
mappings,
|
2019-06-06 15:22:32 -04:00
|
|
|
{source: '</div>', generated: 'i0.ɵɵelementEnd()', sourceUrl: '../test.ts'});
|
2019-02-08 17:10:21 -05:00
|
|
|
|
2019-06-06 15:22:32 -04:00
|
|
|
// TODO: the `ctx_r...` appears to be dependent upon previous tests!!!
|
2019-02-08 17:10:21 -05:00
|
|
|
|
2020-11-19 07:21:01 -05:00
|
|
|
// expectMapping(mappings, {
|
2019-06-06 15:22:32 -04:00
|
|
|
// source: '{{ name }}',
|
|
|
|
// generated: 'i0.ɵɵtextInterpolate(ctx_r0.name)',
|
|
|
|
// sourceUrl: '../test.ts'
|
|
|
|
// });
|
2019-02-08 17:10:21 -05:00
|
|
|
});
|
|
|
|
|
2019-06-06 15:22:32 -04:00
|
|
|
it('should map ng-template [ngIf] scenario', () => {
|
|
|
|
const mappings = compileAndMap(
|
|
|
|
`<ng-template [ngIf]="showMessage()">\n` +
|
|
|
|
` <div>{{ name }}</div>\n` +
|
|
|
|
` <hr>\n` +
|
|
|
|
`</ng-template>`);
|
2019-02-08 17:10:21 -05:00
|
|
|
|
2020-11-19 07:21:01 -05:00
|
|
|
expectMapping(
|
|
|
|
mappings,
|
2019-06-06 15:22:32 -04:00
|
|
|
{source: '<div>', generated: 'i0.ɵɵelementStart(0, "div")', sourceUrl: '../test.ts'});
|
2019-02-08 17:10:21 -05:00
|
|
|
|
2019-06-06 15:22:32 -04:00
|
|
|
// TODO - map the bindings better
|
2019-02-08 17:10:21 -05:00
|
|
|
|
2020-11-19 07:21:01 -05:00
|
|
|
expectMapping(
|
|
|
|
mappings,
|
2019-06-06 15:22:32 -04:00
|
|
|
{source: '</div>', generated: 'i0.ɵɵelementEnd()', sourceUrl: '../test.ts'});
|
2019-02-08 17:10:21 -05:00
|
|
|
|
2019-06-06 15:22:32 -04:00
|
|
|
// TODO: the `ctx_r...` appears to be dependent upon previous tests!!!
|
2019-02-08 17:10:21 -05:00
|
|
|
|
2020-11-19 07:21:01 -05:00
|
|
|
// expectMapping(mappings, {
|
2019-06-06 15:22:32 -04:00
|
|
|
// source: '{{ name }}',
|
|
|
|
// generated: 'i0.ɵɵtextInterpolate(ctx_r0.name)',
|
|
|
|
// sourceUrl: '../test.ts'
|
|
|
|
// });
|
2019-02-08 17:10:21 -05:00
|
|
|
});
|
|
|
|
|
2019-06-06 15:22:32 -04:00
|
|
|
it('should map *ngFor scenario', () => {
|
|
|
|
const mappings = compileAndMap(
|
|
|
|
'<div *ngFor="let item of items; index as i; trackBy: trackByFn">{{ item }}</div>');
|
2019-02-08 17:10:21 -05:00
|
|
|
|
2020-11-19 07:21:01 -05:00
|
|
|
expectMapping(mappings, {
|
2019-06-06 15:22:32 -04:00
|
|
|
source: '<div *ngFor="let item of items; index as i; trackBy: trackByFn">',
|
|
|
|
generated: 'i0.ɵɵelementStart(0, "div")',
|
|
|
|
sourceUrl: '../test.ts'
|
|
|
|
});
|
2019-02-08 17:10:21 -05:00
|
|
|
|
2019-06-06 15:22:32 -04:00
|
|
|
// TODO - map the bindings better
|
2019-02-08 17:10:21 -05:00
|
|
|
|
2020-11-19 07:21:01 -05:00
|
|
|
expectMapping(
|
|
|
|
mappings,
|
2019-06-06 15:22:32 -04:00
|
|
|
{source: '</div>', generated: 'i0.ɵɵelementEnd()', sourceUrl: '../test.ts'});
|
2019-02-08 17:10:21 -05:00
|
|
|
});
|
|
|
|
|
2019-06-06 15:22:32 -04:00
|
|
|
it('should map ng-template [ngFor] scenario', () => {
|
|
|
|
const mappings = compileAndMap(
|
|
|
|
`<ng-template ngFor [ngForOf]="items" let-item>{{ item }}</ng-template>`);
|
2019-02-08 17:10:21 -05:00
|
|
|
|
2019-06-06 15:22:32 -04:00
|
|
|
// TODO - map the bindings better
|
|
|
|
});
|
2019-02-08 17:10:21 -05:00
|
|
|
});
|
|
|
|
|
2019-06-06 15:22:32 -04:00
|
|
|
describe('(content projection)', () => {
|
|
|
|
it('should map default and selected projection', () => {
|
|
|
|
const mappings = compileAndMap(
|
|
|
|
`<h3><ng-content select="title"></ng-content></h3>\n` +
|
|
|
|
`<div><ng-content></ng-content></div>`);
|
|
|
|
|
2020-11-19 07:21:01 -05:00
|
|
|
expectMapping(
|
|
|
|
mappings,
|
2019-06-06 15:22:32 -04:00
|
|
|
{source: '<h3>', generated: 'i0.ɵɵelementStart(0, "h3")', sourceUrl: '../test.ts'});
|
2020-11-19 07:21:01 -05:00
|
|
|
expectMapping(mappings, {
|
2020-08-26 06:56:38 -04:00
|
|
|
source: '<ng-content select="title"></ng-content>',
|
2019-06-06 15:22:32 -04:00
|
|
|
generated: 'i0.ɵɵprojection(1)',
|
|
|
|
sourceUrl: '../test.ts'
|
|
|
|
});
|
2020-11-19 07:21:01 -05:00
|
|
|
expectMapping(
|
|
|
|
mappings, {source: '</h3>', generated: 'i0.ɵɵelementEnd()', sourceUrl: '../test.ts'});
|
|
|
|
expectMapping(
|
|
|
|
mappings,
|
2019-06-06 15:22:32 -04:00
|
|
|
{source: '<div>', generated: 'i0.ɵɵelementStart(2, "div")', sourceUrl: '../test.ts'});
|
2020-11-19 07:21:01 -05:00
|
|
|
expectMapping(mappings, {
|
2020-08-26 06:56:38 -04:00
|
|
|
source: '<ng-content></ng-content>',
|
2019-06-06 15:22:32 -04:00
|
|
|
generated: 'i0.ɵɵprojection(3, 1)',
|
|
|
|
sourceUrl: '../test.ts'
|
|
|
|
});
|
2020-11-19 07:21:01 -05:00
|
|
|
expectMapping(
|
|
|
|
mappings,
|
2019-06-06 15:22:32 -04:00
|
|
|
{source: '</div>', generated: 'i0.ɵɵelementEnd()', sourceUrl: '../test.ts'});
|
|
|
|
});
|
2019-02-08 17:10:21 -05:00
|
|
|
});
|
|
|
|
|
2020-08-31 11:27:44 -04:00
|
|
|
describe('$localize', () => {
|
|
|
|
it('should create simple i18n message source-mapping', () => {
|
|
|
|
const mappings = compileAndMap(`<div i18n>Hello, World!</div>`);
|
2020-11-19 07:21:01 -05:00
|
|
|
expectMapping(mappings, {
|
2020-08-31 11:27:44 -04:00
|
|
|
source: '<div i18n>',
|
|
|
|
generated: 'i0.ɵɵelementStart(0, "div")',
|
|
|
|
sourceUrl: '../test.ts',
|
|
|
|
});
|
2020-11-19 07:21:01 -05:00
|
|
|
expectMapping(mappings, {
|
2020-08-31 11:27:44 -04:00
|
|
|
source: 'Hello, World!',
|
|
|
|
generated: '`Hello, World!`',
|
|
|
|
sourceUrl: '../test.ts',
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should create placeholder source-mappings', () => {
|
|
|
|
const mappings = compileAndMap(`<div i18n>Hello, {{name}}!</div>`);
|
2020-11-19 07:21:01 -05:00
|
|
|
expectMapping(mappings, {
|
2020-08-31 11:27:44 -04:00
|
|
|
source: '<div i18n>',
|
|
|
|
generated: 'i0.ɵɵelementStart(0, "div")',
|
|
|
|
sourceUrl: '../test.ts',
|
|
|
|
});
|
2020-11-19 07:21:01 -05:00
|
|
|
expectMapping(mappings, {
|
2020-08-31 11:27:44 -04:00
|
|
|
source: '</div>',
|
|
|
|
generated: 'i0.ɵɵelementEnd()',
|
|
|
|
sourceUrl: '../test.ts',
|
|
|
|
});
|
2020-11-19 07:21:01 -05:00
|
|
|
expectMapping(mappings, {
|
2020-08-31 11:27:44 -04:00
|
|
|
source: 'Hello, ',
|
|
|
|
generated: '`Hello, ${',
|
|
|
|
sourceUrl: '../test.ts',
|
|
|
|
});
|
2020-11-19 07:21:01 -05:00
|
|
|
expectMapping(mappings, {
|
2020-08-31 11:27:44 -04:00
|
|
|
source: '{{name}}',
|
|
|
|
generated: '"\\uFFFD0\\uFFFD"',
|
|
|
|
sourceUrl: '../test.ts',
|
|
|
|
});
|
2020-11-19 07:21:01 -05:00
|
|
|
expectMapping(mappings, {
|
2020-08-31 11:27:44 -04:00
|
|
|
source: '!',
|
|
|
|
generated: '}:INTERPOLATION:!`',
|
|
|
|
sourceUrl: '../test.ts',
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-11-16 10:02:38 -05:00
|
|
|
it('should correctly handle collapsed whitespace in interpolation placeholder source-mappings',
|
|
|
|
() => {
|
|
|
|
const mappings = compileAndMap(
|
|
|
|
`<div i18n title=" pre-title {{title_value}} post-title" i18n-title> pre-body {{body_value}} post-body</div>`);
|
|
|
|
expectMapping(mappings, {
|
|
|
|
source: '<div i18n title=" pre-title {{title_value}} post-title" i18n-title> ',
|
|
|
|
generated: 'i0.ɵɵelementStart(0, "div", 0)',
|
|
|
|
sourceUrl: '../test.ts',
|
|
|
|
});
|
|
|
|
expectMapping(mappings, {
|
|
|
|
source: '</div>',
|
|
|
|
generated: 'i0.ɵɵelementEnd()',
|
|
|
|
sourceUrl: '../test.ts',
|
|
|
|
});
|
|
|
|
expectMapping(mappings, {
|
|
|
|
source: ' pre-body ',
|
|
|
|
generated: '` pre-body ${',
|
|
|
|
sourceUrl: '../test.ts',
|
|
|
|
});
|
|
|
|
expectMapping(mappings, {
|
|
|
|
source: '{{body_value}}',
|
|
|
|
generated: '"\\uFFFD0\\uFFFD"',
|
|
|
|
sourceUrl: '../test.ts',
|
|
|
|
});
|
|
|
|
expectMapping(mappings, {
|
|
|
|
source: ' post-body',
|
|
|
|
generated: '}:INTERPOLATION: post-body`',
|
|
|
|
sourceUrl: '../test.ts',
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should correctly handle collapsed whitespace in element placeholder source-mappings',
|
|
|
|
() => {
|
|
|
|
const mappings =
|
|
|
|
compileAndMap(`<div i18n>\n pre-p\n <p>\n in-p\n </p>\n post-p\n</div>`);
|
|
|
|
// $localize expressions
|
|
|
|
expectMapping(mappings, {
|
|
|
|
sourceUrl: '../test.ts',
|
|
|
|
source: 'pre-p\n ',
|
|
|
|
generated: '` pre-p ${',
|
|
|
|
});
|
|
|
|
expectMapping(mappings, {
|
|
|
|
sourceUrl: '../test.ts',
|
|
|
|
source: '<p>\n ',
|
|
|
|
generated: '"\\uFFFD#2\\uFFFD"',
|
|
|
|
});
|
|
|
|
expectMapping(mappings, {
|
|
|
|
sourceUrl: '../test.ts',
|
|
|
|
source: 'in-p\n ',
|
|
|
|
generated: '}:START_PARAGRAPH: in-p ${',
|
|
|
|
});
|
|
|
|
expectMapping(mappings, {
|
|
|
|
sourceUrl: '../test.ts',
|
|
|
|
source: '</p>\n ',
|
|
|
|
generated: '"\\uFFFD/#2\\uFFFD"',
|
|
|
|
});
|
|
|
|
expectMapping(mappings, {
|
|
|
|
sourceUrl: '../test.ts',
|
|
|
|
source: 'post-p\n',
|
|
|
|
generated: '}:CLOSE_PARAGRAPH: post-p\n`',
|
|
|
|
});
|
|
|
|
// ivy instructions
|
|
|
|
expectMapping(mappings, {
|
|
|
|
sourceUrl: '../test.ts',
|
|
|
|
source: '<div i18n>\n ',
|
|
|
|
generated: 'i0.ɵɵelementStart(0, "div")',
|
|
|
|
});
|
|
|
|
expectMapping(mappings, {
|
|
|
|
sourceUrl: '../test.ts',
|
|
|
|
source: '<div i18n>\n ',
|
|
|
|
generated: 'i0.ɵɵi18nStart(1, 0)',
|
|
|
|
});
|
|
|
|
expectMapping(mappings, {
|
|
|
|
sourceUrl: '../test.ts',
|
|
|
|
source: '<p>\n in-p\n </p>',
|
|
|
|
generated: 'i0.ɵɵelement(2, "p")',
|
|
|
|
});
|
|
|
|
expectMapping(mappings, {
|
|
|
|
sourceUrl: '../test.ts',
|
|
|
|
source: '</div>',
|
|
|
|
generated: 'i0.ɵɵi18nEnd()',
|
|
|
|
});
|
|
|
|
expectMapping(mappings, {
|
|
|
|
sourceUrl: '../test.ts',
|
|
|
|
source: '</div>',
|
|
|
|
generated: 'i0.ɵɵelementEnd()',
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-08-31 11:27:44 -04:00
|
|
|
it('should create tag (container) placeholder source-mappings', () => {
|
|
|
|
const mappings = compileAndMap(`<div i18n>Hello, <b>World</b>!</div>`);
|
2020-11-19 07:21:01 -05:00
|
|
|
expectMapping(mappings, {
|
2020-08-31 11:27:44 -04:00
|
|
|
source: '<div i18n>',
|
|
|
|
generated: 'i0.ɵɵelementStart(0, "div")',
|
|
|
|
sourceUrl: '../test.ts',
|
|
|
|
});
|
2020-11-19 07:21:01 -05:00
|
|
|
expectMapping(mappings, {
|
2020-08-31 11:27:44 -04:00
|
|
|
source: '</div>',
|
|
|
|
generated: 'i0.ɵɵelementEnd()',
|
|
|
|
sourceUrl: '../test.ts',
|
|
|
|
});
|
2020-11-19 07:21:01 -05:00
|
|
|
expectMapping(mappings, {
|
2020-08-31 11:27:44 -04:00
|
|
|
source: 'Hello, ',
|
|
|
|
generated: '`Hello, ${',
|
|
|
|
sourceUrl: '../test.ts',
|
|
|
|
});
|
2020-11-19 07:21:01 -05:00
|
|
|
expectMapping(mappings, {
|
2020-08-31 11:27:44 -04:00
|
|
|
source: '<b>',
|
|
|
|
generated: '"\\uFFFD#2\\uFFFD"',
|
|
|
|
sourceUrl: '../test.ts',
|
|
|
|
});
|
2020-11-19 07:21:01 -05:00
|
|
|
expectMapping(mappings, {
|
2020-08-31 11:27:44 -04:00
|
|
|
source: 'World',
|
|
|
|
generated: '}:START_BOLD_TEXT:World${',
|
|
|
|
sourceUrl: '../test.ts',
|
|
|
|
});
|
2020-11-19 07:21:01 -05:00
|
|
|
expectMapping(mappings, {
|
2020-08-31 11:27:44 -04:00
|
|
|
source: '</b>',
|
|
|
|
generated: '"\\uFFFD/#2\\uFFFD"',
|
|
|
|
sourceUrl: '../test.ts',
|
|
|
|
});
|
2020-11-19 07:21:01 -05:00
|
|
|
expectMapping(mappings, {
|
2020-08-31 11:27:44 -04:00
|
|
|
source: '!',
|
|
|
|
generated: '}:CLOSE_BOLD_TEXT:!`',
|
|
|
|
sourceUrl: '../test.ts',
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-06-06 15:22:32 -04:00
|
|
|
it('should create (simple string) inline template source-mapping', () => {
|
|
|
|
const mappings = compileAndMap('<div>this is a test</div><div>{{ 1 + 2 }}</div>');
|
2019-02-08 17:10:21 -05:00
|
|
|
|
2019-06-06 15:22:32 -04:00
|
|
|
// Creation mode
|
2020-11-19 07:21:01 -05:00
|
|
|
expectMapping(
|
|
|
|
mappings,
|
2019-06-06 15:22:32 -04:00
|
|
|
{generated: 'i0.ɵɵelementStart(0, "div")', source: '<div>', sourceUrl: '../test.ts'});
|
2020-11-19 07:21:01 -05:00
|
|
|
expectMapping(mappings, {
|
2019-06-06 15:22:32 -04:00
|
|
|
generated: 'i0.ɵɵtext(1, "this is a test")',
|
|
|
|
source: 'this is a test',
|
2019-02-08 17:10:21 -05:00
|
|
|
sourceUrl: '../test.ts'
|
|
|
|
});
|
2020-11-19 07:21:01 -05:00
|
|
|
expectMapping(
|
|
|
|
mappings, {generated: 'i0.ɵɵelementEnd()', source: '</div>', sourceUrl: '../test.ts'});
|
|
|
|
expectMapping(
|
|
|
|
mappings,
|
2019-06-06 15:22:32 -04:00
|
|
|
{generated: 'i0.ɵɵelementStart(2, "div")', source: '<div>', sourceUrl: '../test.ts'});
|
2020-11-19 07:21:01 -05:00
|
|
|
expectMapping(
|
|
|
|
mappings, {generated: 'i0.ɵɵtext(3)', source: '{{ 1 + 2 }}', sourceUrl: '../test.ts'});
|
|
|
|
expectMapping(
|
|
|
|
mappings, {generated: 'i0.ɵɵelementEnd()', source: '</div>', sourceUrl: '../test.ts'});
|
2019-02-08 17:10:21 -05:00
|
|
|
|
2019-06-06 15:22:32 -04:00
|
|
|
// Update mode
|
2020-11-19 07:21:01 -05:00
|
|
|
expectMapping(mappings, {
|
2019-06-06 15:22:32 -04:00
|
|
|
generated: 'i0.ɵɵtextInterpolate(1 + 2)',
|
|
|
|
source: '{{ 1 + 2 }}',
|
|
|
|
sourceUrl: '../test.ts'
|
|
|
|
});
|
2019-02-08 17:10:21 -05:00
|
|
|
});
|
|
|
|
|
2019-06-06 15:22:32 -04:00
|
|
|
it('should create correct inline template source-mapping when the source contains escape sequences',
|
|
|
|
() => {
|
|
|
|
// Note that the escaped double quotes, which need un-escaping to be parsed correctly.
|
|
|
|
const mappings = compileAndMap('<div class=\\"some-class\\">this is a test</div>');
|
2019-02-08 17:10:21 -05:00
|
|
|
|
2020-11-19 07:21:01 -05:00
|
|
|
expectMapping(mappings, {
|
2019-09-23 14:08:51 -04:00
|
|
|
generated: 'i0.ɵɵelementStart(0, "div", 0)',
|
2019-06-06 15:22:32 -04:00
|
|
|
source: '<div class=\\"some-class\\">',
|
|
|
|
sourceUrl: '../test.ts'
|
|
|
|
});
|
2019-02-08 17:10:21 -05:00
|
|
|
|
2019-09-23 14:08:51 -04:00
|
|
|
const attrsMapping =
|
|
|
|
mappings.find(mapping => /consts: \[\[1, "some-class"\]\]/.test(mapping.generated));
|
|
|
|
expect(attrsMapping).toBeDefined();
|
2019-06-06 15:22:32 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
if (tsSourceMapBug29300Fixed()) {
|
|
|
|
describe('External templates (where TS supports source-mapping)', () => {
|
|
|
|
it('should create external template source-mapping', () => {
|
|
|
|
const mappings =
|
|
|
|
compileAndMap('<div>this is a test</div><div>{{ 1 + 2 }}</div>', './dir/test.html');
|
|
|
|
|
|
|
|
// Creation mode
|
2020-11-19 07:21:01 -05:00
|
|
|
expectMapping(mappings, {
|
2019-06-06 15:22:32 -04:00
|
|
|
generated: 'i0.ɵɵelementStart(0, "div")',
|
|
|
|
source: '<div>',
|
|
|
|
sourceUrl: '../dir/test.html'
|
|
|
|
});
|
2020-11-19 07:21:01 -05:00
|
|
|
expectMapping(mappings, {
|
2019-06-06 15:22:32 -04:00
|
|
|
generated: 'i0.ɵɵtext(1, "this is a test")',
|
|
|
|
source: 'this is a test',
|
|
|
|
sourceUrl: '../dir/test.html'
|
|
|
|
});
|
2020-11-19 07:21:01 -05:00
|
|
|
expectMapping(
|
|
|
|
mappings,
|
2019-06-06 15:22:32 -04:00
|
|
|
{generated: 'i0.ɵɵelementEnd()', source: '</div>', sourceUrl: '../dir/test.html'});
|
2020-11-19 07:21:01 -05:00
|
|
|
expectMapping(mappings, {
|
2019-06-06 15:22:32 -04:00
|
|
|
generated: 'i0.ɵɵelementStart(2, "div")',
|
|
|
|
source: '<div>',
|
|
|
|
sourceUrl: '../dir/test.html'
|
|
|
|
});
|
2020-11-19 07:21:01 -05:00
|
|
|
expectMapping(
|
|
|
|
mappings,
|
2019-06-06 15:22:32 -04:00
|
|
|
{generated: 'i0.ɵɵtext(3)', source: '{{ 1 + 2 }}', sourceUrl: '../dir/test.html'});
|
2020-11-19 07:21:01 -05:00
|
|
|
expectMapping(
|
|
|
|
mappings,
|
2019-06-06 15:22:32 -04:00
|
|
|
{generated: 'i0.ɵɵelementEnd()', source: '</div>', sourceUrl: '../dir/test.html'});
|
|
|
|
|
|
|
|
// Update mode
|
2020-11-19 07:21:01 -05:00
|
|
|
expectMapping(mappings, {
|
2019-06-06 15:22:32 -04:00
|
|
|
generated: 'i0.ɵɵtextInterpolate(1 + 2)',
|
|
|
|
source: '{{ 1 + 2 }}',
|
|
|
|
sourceUrl: '../dir/test.html'
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should create correct mappings when templateUrl is in a different rootDir', () => {
|
|
|
|
const mappings = compileAndMap(
|
|
|
|
'<div>this is a test</div><div>{{ 1 + 2 }}</div>', 'extraRootDir/test.html');
|
|
|
|
|
|
|
|
// Creation mode
|
2020-11-19 07:21:01 -05:00
|
|
|
expectMapping(mappings, {
|
2019-06-06 15:22:32 -04:00
|
|
|
generated: 'i0.ɵɵelementStart(0, "div")',
|
|
|
|
source: '<div>',
|
|
|
|
sourceUrl: '../extraRootDir/test.html'
|
|
|
|
});
|
2020-11-19 07:21:01 -05:00
|
|
|
expectMapping(mappings, {
|
2019-06-06 15:22:32 -04:00
|
|
|
generated: 'i0.ɵɵtext(1, "this is a test")',
|
|
|
|
source: 'this is a test',
|
|
|
|
sourceUrl: '../extraRootDir/test.html'
|
|
|
|
});
|
2020-11-19 07:21:01 -05:00
|
|
|
expectMapping(mappings, {
|
2019-06-06 15:22:32 -04:00
|
|
|
generated: 'i0.ɵɵelementEnd()',
|
|
|
|
source: '</div>',
|
|
|
|
sourceUrl: '../extraRootDir/test.html'
|
|
|
|
});
|
2020-11-19 07:21:01 -05:00
|
|
|
expectMapping(mappings, {
|
2019-06-06 15:22:32 -04:00
|
|
|
generated: 'i0.ɵɵelementStart(2, "div")',
|
|
|
|
source: '<div>',
|
|
|
|
sourceUrl: '../extraRootDir/test.html'
|
|
|
|
});
|
2020-11-19 07:21:01 -05:00
|
|
|
expectMapping(mappings, {
|
2019-06-06 15:22:32 -04:00
|
|
|
generated: 'i0.ɵɵtext(3)',
|
|
|
|
source: '{{ 1 + 2 }}',
|
|
|
|
sourceUrl: '../extraRootDir/test.html'
|
|
|
|
});
|
2020-11-19 07:21:01 -05:00
|
|
|
expectMapping(mappings, {
|
2019-06-06 15:22:32 -04:00
|
|
|
generated: 'i0.ɵɵelementEnd()',
|
|
|
|
source: '</div>',
|
|
|
|
sourceUrl: '../extraRootDir/test.html'
|
|
|
|
});
|
|
|
|
|
|
|
|
// Update mode
|
2020-11-19 07:21:01 -05:00
|
|
|
expectMapping(mappings, {
|
2019-06-06 15:22:32 -04:00
|
|
|
generated: 'i0.ɵɵtextInterpolate(1 + 2)',
|
|
|
|
source: '{{ 1 + 2 }}',
|
|
|
|
sourceUrl: '../extraRootDir/test.html'
|
|
|
|
});
|
2019-02-08 17:10:21 -05:00
|
|
|
});
|
|
|
|
});
|
2019-06-06 15:22:32 -04:00
|
|
|
}
|
2019-02-08 17:10:21 -05:00
|
|
|
|
2020-04-07 15:43:43 -04:00
|
|
|
function compileAndMap(template: string, templateUrl: string|null = null) {
|
2019-06-06 15:22:32 -04:00
|
|
|
const templateConfig = templateUrl ? `templateUrl: '${templateUrl}'` :
|
|
|
|
('template: `' + template.replace(/`/g, '\\`') + '`');
|
|
|
|
env.write('test.ts', `
|
2019-02-08 17:10:21 -05:00
|
|
|
import {Component} from '@angular/core';
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'test-cmp',
|
|
|
|
${templateConfig}
|
|
|
|
})
|
|
|
|
export class TestCmp {}
|
|
|
|
`);
|
2019-06-06 15:22:32 -04:00
|
|
|
if (templateUrl) {
|
|
|
|
env.write(templateUrl, template);
|
|
|
|
}
|
|
|
|
env.driveMain();
|
|
|
|
return getMappedSegments(env, 'test.js');
|
2019-02-08 17:10:21 -05:00
|
|
|
}
|
2019-06-06 15:22:32 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper function for debugging failed mappings.
|
|
|
|
* This lays out the segment mappings in the console to make it easier to compare.
|
|
|
|
*/
|
|
|
|
function dumpMappings(mappings: SegmentMapping[]) {
|
|
|
|
mappings.forEach(map => {
|
|
|
|
// tslint:disable-next-line:no-console
|
|
|
|
console.log(
|
|
|
|
padValue(map.sourceUrl, 20, 0) + ' : ' + padValue(inspect(map.source), 100, 23) +
|
|
|
|
' : ' + inspect(map.generated));
|
|
|
|
});
|
|
|
|
function padValue(value: string, max: number, start: number) {
|
|
|
|
const padding = value.length > max ? ('\n' +
|
|
|
|
' '.repeat(max + start)) :
|
|
|
|
' '.repeat(max - value.length);
|
|
|
|
return value + padding;
|
|
|
|
}
|
2019-02-08 17:10:21 -05:00
|
|
|
}
|
2020-11-19 07:21:01 -05:00
|
|
|
|
|
|
|
function expectMapping(mappings: SegmentMapping[], expected: SegmentMapping): void {
|
|
|
|
if (mappings.some(
|
|
|
|
m => m.generated === expected.generated && m.source === expected.source &&
|
|
|
|
m.sourceUrl === expected.sourceUrl)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const matchingGenerated = mappings.filter(m => m.generated === expected.generated);
|
|
|
|
const matchingSource = mappings.filter(m => m.source === expected.source);
|
|
|
|
|
|
|
|
const message = [
|
|
|
|
'Expected mappings to contain the following mapping',
|
|
|
|
prettyPrintMapping(expected),
|
|
|
|
];
|
|
|
|
if (matchingGenerated.length > 0) {
|
|
|
|
message.push('');
|
|
|
|
message.push('There are the following mappings that match the generated text:');
|
|
|
|
matchingGenerated.forEach(m => message.push(prettyPrintMapping(m)));
|
|
|
|
}
|
|
|
|
if (matchingSource.length > 0) {
|
|
|
|
message.push('');
|
|
|
|
message.push('There are the following mappings that match the source text:');
|
|
|
|
matchingSource.forEach(m => message.push(prettyPrintMapping(m)));
|
|
|
|
}
|
|
|
|
|
|
|
|
fail(message.join('\n'));
|
|
|
|
}
|
|
|
|
|
|
|
|
function prettyPrintMapping(mapping: SegmentMapping): string {
|
|
|
|
return [
|
|
|
|
'{',
|
|
|
|
` generated: ${JSON.stringify(mapping.generated)}`,
|
|
|
|
` source: ${JSON.stringify(mapping.source)}`,
|
|
|
|
` sourceUrl: ${JSON.stringify(mapping.sourceUrl)}`,
|
|
|
|
'}',
|
|
|
|
].join('\n');
|
|
|
|
}
|
2019-06-06 15:22:32 -04:00
|
|
|
});
|
2019-02-08 17:10:21 -05:00
|
|
|
});
|