mirror of
https://github.com/angular/angular
synced 2026-05-24 09:28:37 +00:00
This commit removes the View Engine runtime. Itself, this change is relatively straightforward, but it represents the final step in a multi-year journey. It's only possible due to the hard work of many current and former team members and collaborators, who are too numerous to list here. Co-authored-by: Alan Agius <alan.agius4@gmail.com> Co-authored-by: Andrew Kushnir <akushnir@google.com> Co-authored-by: Andrew Scott <atscott01@gmail.com> Co-authored-by: Andrew Seguin <andrewjs@google.com> Co-authored-by: Cédric Exbrayat <cedric@ninja-squad.com> Co-authored-by: Charles Lyding <19598772+clydin@users.noreply.github.com> Co-authored-by: Dave Shevitz <dshevitz@google.com> Co-authored-by: Doug Parker <dgp1130@users.noreply.github.com> Co-authored-by: Dylan Hunn <dylhunn@gmail.com> Co-authored-by: Emma Twersky <emmatwersky@google.com> Co-authored-by: George Kalpakas <kalpakas.g@gmail.com> Co-authored-by: Igor Minar <iminar@google.com> Co-authored-by: Jeremy Elbourn <jelbourn@google.com> Co-authored-by: Jessica Janiuk <jessicajaniuk@google.com> Co-authored-by: JiaLiPassion <JiaLi.Passion@gmail.com> Co-authored-by: Joey Perrott <josephperrott@gmail.com> Co-authored-by: Joost Koehoorn <joost.koehoorn@gmail.com> Co-authored-by: Kristiyan Kostadinov <crisbeto@abv.bg> Co-authored-by: Madleina Scheidegger <mscheid@google.com> Co-authored-by: Mark Thompson <2554588+MarkTechson@users.noreply.github.com> Co-authored-by: Minko Gechev <mgechev@gmail.com> Co-authored-by: Paul Gschwendtner <paulgschwendtner@gmail.com> Co-authored-by: Pawel Kozlowski <pkozlowski.opensource@gmail.com> Co-authored-by: Pete Bacon Darwin <pete@bacondarwin.com> Co-authored-by: Wagner Maciel <wagnermaciel@google.com> Co-authored-by: Zach Arend <zachzach@google.com> PR Close #43884
68 lines
2.6 KiB
TypeScript
68 lines
2.6 KiB
TypeScript
/**
|
|
* @license
|
|
* Copyright Google LLC 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 {EmitterVisitorContext} from '@angular/compiler/src/output/abstract_emitter';
|
|
import * as o from '@angular/compiler/src/output/output_ast';
|
|
import {JitEmitterVisitor, JitEvaluator} from '@angular/compiler/src/output/output_jit';
|
|
import {R3JitReflector} from '@angular/compiler/src/render3/r3_jit';
|
|
import {newArray} from '@angular/compiler/src/util';
|
|
|
|
{
|
|
describe('Output JIT', () => {
|
|
describe('regression', () => {
|
|
it('should generate unique argument names', () => {
|
|
const externalIds = newArray(10, 1).map(
|
|
(_, index) =>
|
|
new o.ExternalReference('@angular/core', `id_${index}_`, {name: `id_${index}_`}));
|
|
const externalIds1 = newArray(10, 1).map(
|
|
(_, index) =>
|
|
new o.ExternalReference('@angular/core', `id_${index}_1`, {name: `id_${index}_1`}));
|
|
const ctx = EmitterVisitorContext.createRoot();
|
|
const reflectorContext: {[key: string]: string} = {};
|
|
for (const {name} of externalIds) {
|
|
reflectorContext[name!] = name!;
|
|
}
|
|
for (const {name} of externalIds1) {
|
|
reflectorContext[name!] = name!;
|
|
}
|
|
const converter = new JitEmitterVisitor(new R3JitReflector(reflectorContext));
|
|
converter.visitAllStatements(
|
|
[o.literalArr([...externalIds1, ...externalIds].map(id => o.importExpr(id))).toStmt()],
|
|
ctx);
|
|
const args = converter.getArgs();
|
|
expect(Object.keys(args).length).toBe(20);
|
|
});
|
|
});
|
|
|
|
it('should use strict mode', () => {
|
|
const evaluator = new JitEvaluator();
|
|
expect(() => {
|
|
evaluator.evaluateStatements(
|
|
'http://angular.io/something.ts',
|
|
[
|
|
// Set an undeclared variable
|
|
// foo = "bar";
|
|
o.variable('foo').equals(o.literal('bar')).toStmt(),
|
|
],
|
|
new R3JitReflector({}), false);
|
|
}).toThrowError();
|
|
});
|
|
|
|
it('should not add more than one strict mode statement if there is already one present', () => {
|
|
const converter = new JitEmitterVisitor(new R3JitReflector({}));
|
|
const ctx = EmitterVisitorContext.createRoot();
|
|
converter.visitAllStatements(
|
|
[
|
|
o.literal('use strict').toStmt(),
|
|
],
|
|
ctx);
|
|
const matches = ctx.toSource().match(/'use strict';/g)!;
|
|
expect(matches.length).toBe(1);
|
|
});
|
|
});
|
|
}
|