8
8
9
9
import { EmitterVisitorContext } from '@angular/compiler/src/output/abstract_emitter' ;
10
10
import * as o from '@angular/compiler/src/output/output_ast' ;
11
- import { JitEmitterVisitor } from '@angular/compiler/src/output/output_jit' ;
11
+ import { JitEmitterVisitor , JitEvaluator } from '@angular/compiler/src/output/output_jit' ;
12
+ import { R3JitReflector } from '@angular/compiler/src/render3/r3_jit' ;
12
13
import { JitReflector } from '@angular/platform-browser-dynamic/src/compiler_reflector' ;
13
14
14
15
const anotherModuleUrl = 'somePackage/someOtherPath' ;
@@ -32,5 +33,31 @@ const anotherModuleUrl = 'somePackage/someOtherPath';
32
33
expect ( Object . keys ( args ) . length ) . toBe ( 20 ) ;
33
34
} ) ;
34
35
} ) ;
36
+
37
+ it ( 'should use strict mode' , ( ) => {
38
+ const evaluator = new JitEvaluator ( ) ;
39
+ expect ( ( ) => {
40
+ evaluator . evaluateStatements (
41
+ 'http://angular.io/something.ts' ,
42
+ [
43
+ // Set an undeclared variable
44
+ // foo = "bar";
45
+ o . variable ( 'foo' ) . equals ( o . literal ( 'bar' ) ) . toStmt ( ) ,
46
+ ] ,
47
+ new R3JitReflector ( { } ) , false ) ;
48
+ } ) . toThrowError ( ) ;
49
+ } ) ;
50
+
51
+ it ( 'should not add more than one strict mode statement if there is already one present' , ( ) => {
52
+ const converter = new JitEmitterVisitor ( new JitReflector ( ) ) ;
53
+ const ctx = EmitterVisitorContext . createRoot ( ) ;
54
+ converter . visitAllStatements (
55
+ [
56
+ o . literal ( 'use strict' ) . toStmt ( ) ,
57
+ ] ,
58
+ ctx ) ;
59
+ const matches = ctx . toSource ( ) . match ( / ' u s e s t r i c t ' ; / g) ! ;
60
+ expect ( matches . length ) . toBe ( 1 ) ;
61
+ } ) ;
35
62
} ) ;
36
- }
63
+ }
0 commit comments