fix: ensure strict mode when evaluating in JIT (#30122)
PR Close #30122
This commit is contained in:

committed by
Alex Rickabaugh

parent
728db88280
commit
452f121486
@ -8,7 +8,8 @@
|
||||
|
||||
import {EmitterVisitorContext} from '@angular/compiler/src/output/abstract_emitter';
|
||||
import * as o from '@angular/compiler/src/output/output_ast';
|
||||
import {JitEmitterVisitor} from '@angular/compiler/src/output/output_jit';
|
||||
import {JitEmitterVisitor, JitEvaluator} from '@angular/compiler/src/output/output_jit';
|
||||
import {R3JitReflector} from '@angular/compiler/src/render3/r3_jit';
|
||||
import {JitReflector} from '@angular/platform-browser-dynamic/src/compiler_reflector';
|
||||
|
||||
const anotherModuleUrl = 'somePackage/someOtherPath';
|
||||
@ -32,5 +33,31 @@ const anotherModuleUrl = 'somePackage/someOtherPath';
|
||||
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 JitReflector());
|
||||
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);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user