OLD | NEW |
| (Empty) |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | |
2 // for details. All rights reserved. Use of this source code is governed by a | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 | |
5 library dev_compiler.test.transformer.transformer_test; | |
6 | |
7 import 'package:barback/barback.dart' show BarbackMode, BarbackSettings; | |
8 import 'package:dev_compiler/transformer.dart'; | |
9 import 'package:dev_compiler/src/compiler.dart' show defaultRuntimeFiles; | |
10 import 'package:test/test.dart'; | |
11 import 'package:transformer_test/utils.dart'; | |
12 | |
13 makePhases([Map config = const {}]) => [ | |
14 [ | |
15 new DdcTransformer.asPlugin( | |
16 new BarbackSettings(config, BarbackMode.RELEASE)) | |
17 ] | |
18 ]; | |
19 | |
20 final Map<String, String> runtimeInput = new Map.fromIterable( | |
21 defaultRuntimeFiles, | |
22 key: (f) => 'dev_compiler|lib/runtime/$f', | |
23 value: (_) => ''); | |
24 | |
25 Map<String, String> createInput(Map<String, String> input) => | |
26 {}..addAll(input)..addAll(runtimeInput); | |
27 | |
28 void main() { | |
29 group('$DdcTransformer', () { | |
30 testPhases( | |
31 r'compiles simple code', | |
32 makePhases(), | |
33 createInput({ | |
34 'foo|lib/Foo.dart': r''' | |
35 class Foo {} | |
36 ''' | |
37 }), | |
38 { | |
39 'foo|web/foo/Foo.js': r''' | |
40 dart_library.library('foo/Foo', null, /* Imports */[ | |
41 'dart/_runtime', | |
42 'dart/core' | |
43 ], /* Lazy imports */[ | |
44 ], function(exports, dart, core) { | |
45 'use strict'; | |
46 let dartx = dart.dartx; | |
47 class Foo extends core.Object {} | |
48 // Exports: | |
49 exports.Foo = Foo; | |
50 }); | |
51 //# sourceMappingURL=Foo.js.map | |
52 ''' | |
53 .trimLeft() | |
54 }); | |
55 | |
56 testPhases( | |
57 r'honours arguments', | |
58 makePhases({ | |
59 'args': ['--destructure-named-params', '--modules=es6'] | |
60 }), | |
61 createInput({ | |
62 'foo|lib/Foo.dart': r''' | |
63 int foo({String s : '?'}) {} | |
64 ''' | |
65 }), | |
66 { | |
67 'foo|web/foo/Foo.js': r''' | |
68 const exports = {}; | |
69 import dart from "../dart/_runtime"; | |
70 import core from "../dart/core"; | |
71 let dartx = dart.dartx; | |
72 function foo({s = '?'} = {}) { | |
73 } | |
74 dart.fn(foo, core.int, [], {s: core.String}); | |
75 // Exports: | |
76 exports.foo = foo; | |
77 export default exports; | |
78 //# sourceMappingURL=Foo.js.map | |
79 ''' | |
80 .trimLeft() | |
81 }); | |
82 | |
83 testPhases( | |
84 'forwards errors', | |
85 makePhases(), | |
86 createInput({ | |
87 'foo|lib/Foo.dart': r''' | |
88 foo() { | |
89 var x = 1; | |
90 x = '2'; | |
91 } | |
92 ''' | |
93 }), | |
94 {}, | |
95 [ | |
96 "warning: A value of type \'String\' cannot be assigned to a variable
of type \'int\' (package:foo/Foo.dart 3 19)", | |
97 "error: Type check failed: '2' (String) is not of type int (package:fo
o/Foo.dart 3 19)" | |
98 ]); | |
99 }); | |
100 } | |
OLD | NEW |