Skip to content
This repository was archived by the owner on Feb 22, 2018. It is now read-only.

Commit a087fc7

Browse files
author
Olivier Chafik
committed
Allow disabling named param destructuring with --destructure-named-params (issue #396)
Right now one also needs to regenerate the runtime (see #397): ./tools/build_sdk --no-destructure-named-params
1 parent 444356c commit a087fc7

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

lib/src/codegen/js_codegen.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1990,7 +1990,8 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ClosureAnnotator {
19901990
/// We cannot destructure named params that clash with JS reserved names:
19911991
/// see discussion in https://github.com/dart-lang/dev_compiler/issues/392.
19921992
bool _isDestructurableNamedParam(FormalParameter param) =>
1993-
_isNamedParam(param) && !invalidVariableName(param.identifier.name);
1993+
_isNamedParam(param) && !invalidVariableName(param.identifier.name) &&
1994+
options.destructureNamedParams;
19941995

19951996
@override
19961997
List<JS.Parameter> visitFormalParameterList(FormalParameterList node) =>

lib/src/options.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import 'package:yaml/yaml.dart';
1515

1616
const String _V8_BINARY_DEFAULT = 'node';
1717
const bool _CLOSURE_DEFAULT = false;
18+
const bool _DESTRUCTURE_NAMED_PARAMS_DEFAULT = true;
1819

1920
/// Options used to set up Source URI resolution in the analysis context.
2021
class SourceResolverOptions {
@@ -69,6 +70,9 @@ class CodegenOptions {
6970
/// Emit Closure Compiler-friendly code.
7071
final bool closure;
7172

73+
/// Enable ES6 destructuring of named parameters.
74+
final bool destructureNamedParams;
75+
7276
/// Whether to emit a workaround for missing arrow function bind-this in
7377
/// other V8 builds
7478
final bool arrowFnBindThisWorkaround;
@@ -81,6 +85,7 @@ class CodegenOptions {
8185
{this.emitSourceMaps: true,
8286
this.forceCompile: false,
8387
this.closure: _CLOSURE_DEFAULT,
88+
this.destructureNamedParams: _DESTRUCTURE_NAMED_PARAMS_DEFAULT,
8489
this.outputDir,
8590
this.arrowFnBindThisWorkaround: false,
8691
this.moduleFormat: 'dart'});
@@ -231,6 +236,7 @@ CompilerOptions parseOptions(List<String> argv, {bool forceOutDir: false}) {
231236
emitSourceMaps: args['source-maps'],
232237
forceCompile: args['force-compile'] || serverMode,
233238
closure: args['closure'],
239+
destructureNamedParams: args['destructure-named-params'],
234240
outputDir: outputDir,
235241
arrowFnBindThisWorkaround: args['arrow-fn-bind-this'],
236242
moduleFormat: args['modules']),
@@ -327,6 +333,9 @@ final ArgParser argParser = new ArgParser()
327333
..addFlag('closure',
328334
help: 'Emit Closure Compiler-friendly code (experimental)',
329335
defaultsTo: _CLOSURE_DEFAULT)
336+
..addFlag('destructure-named-params',
337+
help: 'Destructure named parameters (requires ES6-enabled runtime)',
338+
defaultsTo: _DESTRUCTURE_NAMED_PARAMS_DEFAULT)
330339
..addFlag('force-compile',
331340
abbr: 'f', help: 'Compile code with static errors', defaultsTo: false)
332341
..addOption('log', abbr: 'l', help: 'Logging level (defaults to warning)')

0 commit comments

Comments
 (0)