Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(413)

Side by Side Diff: lib/src/compiler/compiler.dart

Issue 1988023008: Name and hoist types (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Address comments Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « lib/src/compiler/code_generator.dart ('k') | lib/src/compiler/type_utilities.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 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 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 import 'dart:collection' show HashSet; 5 import 'dart:collection' show HashSet;
6 import 'package:args/args.dart' show ArgParser, ArgResults; 6 import 'package:args/args.dart' show ArgParser, ArgResults;
7 import 'package:analyzer/analyzer.dart' 7 import 'package:analyzer/analyzer.dart'
8 show 8 show
9 AnalysisError, 9 AnalysisError,
10 CompilationUnit, 10 CompilationUnit,
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 152
153 /// Whether to preserve metdata only accessible via mirrors 153 /// Whether to preserve metdata only accessible via mirrors
154 final bool emitMetadata; 154 final bool emitMetadata;
155 155
156 /// Whether to force compilation of code with static errors. 156 /// Whether to force compilation of code with static errors.
157 final bool unsafeForceCompile; 157 final bool unsafeForceCompile;
158 158
159 /// Whether to emit Closure Compiler-friendly code. 159 /// Whether to emit Closure Compiler-friendly code.
160 final bool closure; 160 final bool closure;
161 161
162 /// Hoist the types at instance creation sites
163 final bool hoistInstanceCreation;
164
165 /// Hoist types from class signatures
166 final bool hoistSignatureTypes;
167
168 /// Name types in type tests
169 final bool nameTypeTests;
170
171 /// Hoist types in type tests
172 final bool hoistTypeTests;
173
162 /// Enable ES6 destructuring of named parameters. Off by default. 174 /// Enable ES6 destructuring of named parameters. Off by default.
163 /// 175 ///
164 /// Older V8 versions do not accept default values with destructuring in 176 /// Older V8 versions do not accept default values with destructuring in
165 /// arrow functions yet (e.g. `({a} = {}) => 1`) but happily accepts them 177 /// arrow functions yet (e.g. `({a} = {}) => 1`) but happily accepts them
166 /// with regular functions (e.g. `function({a} = {}) { return 1 }`). 178 /// with regular functions (e.g. `function({a} = {}) { return 1 }`).
167 /// 179 ///
168 /// Supporting the syntax: 180 /// Supporting the syntax:
169 /// * Chrome Canary (51) 181 /// * Chrome Canary (51)
170 /// * Firefox 182 /// * Firefox
171 /// 183 ///
172 /// Not yet supporting: 184 /// Not yet supporting:
173 /// * Atom (1.5.4) 185 /// * Atom (1.5.4)
174 /// * Electron (0.36.3) 186 /// * Electron (0.36.3)
175 // TODO(ochafik): Simplify this code when our target platforms catch up. 187 // TODO(ochafik): Simplify this code when our target platforms catch up.
176 final bool destructureNamedParams; 188 final bool destructureNamedParams;
177 189
178 /// Which module format to support. 190 /// Which module format to support.
179 /// Currently 'es6' and 'legacy' are supported. 191 /// Currently 'es6' and 'legacy' are supported.
180 final ModuleFormat moduleFormat; 192 final ModuleFormat moduleFormat;
181 193
182 const CompilerOptions( 194 const CompilerOptions(
183 {this.sourceMap: true, 195 {this.sourceMap: true,
184 this.sourceMapComment: true, 196 this.sourceMapComment: true,
185 this.summarizeApi: true, 197 this.summarizeApi: true,
186 this.unsafeForceCompile: false, 198 this.unsafeForceCompile: false,
187 this.emitMetadata: false, 199 this.emitMetadata: false,
188 this.closure: false, 200 this.closure: false,
189 this.destructureNamedParams: false, 201 this.destructureNamedParams: false,
190 this.moduleFormat: ModuleFormat.legacy}); 202 this.moduleFormat: ModuleFormat.legacy,
203 this.hoistInstanceCreation: true,
204 this.hoistSignatureTypes: false,
205 this.nameTypeTests: true,
206 this.hoistTypeTests: true});
191 207
192 CompilerOptions.fromArguments(ArgResults args) 208 CompilerOptions.fromArguments(ArgResults args)
193 : sourceMap = args['source-map'], 209 : sourceMap = args['source-map'],
194 sourceMapComment = args['source-map-comment'], 210 sourceMapComment = args['source-map-comment'],
195 summarizeApi = args['summarize'], 211 summarizeApi = args['summarize'],
196 unsafeForceCompile = args['unsafe-force-compile'], 212 unsafeForceCompile = args['unsafe-force-compile'],
197 emitMetadata = args['emit-metadata'], 213 emitMetadata = args['emit-metadata'],
198 closure = args['closure-experimental'], 214 closure = args['closure-experimental'],
199 destructureNamedParams = args['destructure-named-params'], 215 destructureNamedParams = args['destructure-named-params'],
200 moduleFormat = parseModuleFormat(args['modules']); 216 moduleFormat = parseModuleFormat(args['modules']),
217 hoistInstanceCreation = args['hoist-instance-creation'],
218 hoistSignatureTypes = args['hoist-signature-types'],
219 nameTypeTests = args['name-type-tests'],
220 hoistTypeTests = args['hoist-type-tests'];
201 221
202 static ArgParser addArguments(ArgParser parser) => parser 222 static ArgParser addArguments(ArgParser parser) => parser
203 ..addFlag('summarize', help: 'emit an API summary file', defaultsTo: true) 223 ..addFlag('summarize', help: 'emit an API summary file', defaultsTo: true)
204 ..addFlag('source-map', help: 'emit source mapping', defaultsTo: true) 224 ..addFlag('source-map', help: 'emit source mapping', defaultsTo: true)
205 ..addFlag('source-map-comment', 225 ..addFlag('source-map-comment',
206 help: 'adds a sourceMappingURL comment to the end of the JS,\n' 226 help: 'adds a sourceMappingURL comment to the end of the JS,\n'
207 'disable if using X-SourceMap header', 227 'disable if using X-SourceMap header',
208 defaultsTo: true) 228 defaultsTo: true)
209 ..addOption('modules', 229 ..addOption('modules',
210 help: 'module pattern to emit', 230 help: 'module pattern to emit',
211 allowed: ['es6', 'legacy', 'node'], 231 allowed: ['es6', 'legacy', 'node'],
212 allowedHelp: { 232 allowedHelp: {
213 'es6': 'es6 modules', 233 'es6': 'es6 modules',
214 'legacy': 'a custom format used by dartdevc, similar to AMD', 234 'legacy': 'a custom format used by dartdevc, similar to AMD',
215 'node': 'node.js modules (https://nodejs.org/api/modules.html)' 235 'node': 'node.js modules (https://nodejs.org/api/modules.html)'
216 }, 236 },
217 defaultsTo: 'legacy') 237 defaultsTo: 'legacy')
218 ..addFlag('emit-metadata', 238 ..addFlag('emit-metadata',
219 help: 'emit metadata annotations queriable via mirrors', 239 help: 'emit metadata annotations queriable via mirrors',
220 defaultsTo: false) 240 defaultsTo: false)
221 ..addFlag('closure-experimental', 241 ..addFlag('closure-experimental',
222 help: 'emit Closure Compiler-friendly code (experimental)', 242 help: 'emit Closure Compiler-friendly code (experimental)',
223 defaultsTo: false) 243 defaultsTo: false)
224 ..addFlag('destructure-named-params', 244 ..addFlag('destructure-named-params',
225 help: 'Destructure named parameters', defaultsTo: false) 245 help: 'Destructure named parameters', defaultsTo: false)
226 ..addFlag('unsafe-force-compile', 246 ..addFlag('unsafe-force-compile',
227 help: 'Compile code even if it has errors. ಠ_ಠ\n' 247 help: 'Compile code even if it has errors. ಠ_ಠ\n'
228 'This has undefined behavior!', 248 'This has undefined behavior!',
229 defaultsTo: false); 249 defaultsTo: false)
250 ..addFlag('hoist-instance-creation',
Jennifer Messerly 2016/05/25 01:24:18 Should we hide these options from the "--help"? I
251 help: 'Hoist the class type from generic instance creations',
252 defaultsTo: true)
253 ..addFlag('hoist-signature-types',
254 help: 'Hoist types from class signatures', defaultsTo: false)
255 ..addFlag('name-type-tests',
256 help: 'Name types used in type tests', defaultsTo: true)
257 ..addFlag('hoist-type-tests',
258 help: 'Hoist types used in type tests', defaultsTo: true);
230 } 259 }
231 260
232 /// A unit of Dart code that can be built into a single JavaScript module. 261 /// A unit of Dart code that can be built into a single JavaScript module.
233 class BuildUnit { 262 class BuildUnit {
234 /// The name of this module. 263 /// The name of this module.
235 final String name; 264 final String name;
236 265
237 /// Build root. All library names are relative to this path/prefix. 266 /// Build root. All library names are relative to this path/prefix.
238 final String buildRoot; 267 final String buildRoot;
239 268
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 } 337 }
309 } 338 }
310 339
311 /// (Public for tests) the error code used when a part is missing. 340 /// (Public for tests) the error code used when a part is missing.
312 final missingPartErrorCode = const CompileTimeErrorCode( 341 final missingPartErrorCode = const CompileTimeErrorCode(
313 'MISSING_PART', 'The part was not supplied as an input to the compiler.'); 342 'MISSING_PART', 'The part was not supplied as an input to the compiler.');
314 343
315 /// (Public for tests) the error code used when a part is unused. 344 /// (Public for tests) the error code used when a part is unused.
316 final unusedPartWarningCode = const StaticWarningCode( 345 final unusedPartWarningCode = const StaticWarningCode(
317 'UNUSED_PART', 'The part was not used by any libraries being compiled.'); 346 'UNUSED_PART', 'The part was not used by any libraries being compiled.');
OLDNEW
« no previous file with comments | « lib/src/compiler/code_generator.dart ('k') | lib/src/compiler/type_utilities.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698