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

Allow disabling named param destructuring with --destructure-named-params (issue #396) #398

Merged
merged 1 commit into from
Dec 11, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/src/codegen/js_codegen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1990,7 +1990,8 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ClosureAnnotator {
/// We cannot destructure named params that clash with JS reserved names:
/// see discussion in https://github.com/dart-lang/dev_compiler/issues/392.
bool _isDestructurableNamedParam(FormalParameter param) =>
_isNamedParam(param) && !invalidVariableName(param.identifier.name);
_isNamedParam(param) && !invalidVariableName(param.identifier.name) &&
options.destructureNamedParams;

@override
List<JS.Parameter> visitFormalParameterList(FormalParameterList node) =>
Expand Down
9 changes: 9 additions & 0 deletions lib/src/options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import 'package:yaml/yaml.dart';

const String _V8_BINARY_DEFAULT = 'node';
const bool _CLOSURE_DEFAULT = false;
const bool _DESTRUCTURE_NAMED_PARAMS_DEFAULT = true;

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

/// Enable ES6 destructuring of named parameters.
final bool destructureNamedParams;

/// Whether to emit a workaround for missing arrow function bind-this in
/// other V8 builds
final bool arrowFnBindThisWorkaround;
Expand All @@ -81,6 +85,7 @@ class CodegenOptions {
{this.emitSourceMaps: true,
this.forceCompile: false,
this.closure: _CLOSURE_DEFAULT,
this.destructureNamedParams: _DESTRUCTURE_NAMED_PARAMS_DEFAULT,
this.outputDir,
this.arrowFnBindThisWorkaround: false,
this.moduleFormat: 'dart'});
Expand Down Expand Up @@ -231,6 +236,7 @@ CompilerOptions parseOptions(List<String> argv, {bool forceOutDir: false}) {
emitSourceMaps: args['source-maps'],
forceCompile: args['force-compile'] || serverMode,
closure: args['closure'],
destructureNamedParams: args['destructure-named-params'],
outputDir: outputDir,
arrowFnBindThisWorkaround: args['arrow-fn-bind-this'],
moduleFormat: args['modules']),
Expand Down Expand Up @@ -327,6 +333,9 @@ final ArgParser argParser = new ArgParser()
..addFlag('closure',
help: 'Emit Closure Compiler-friendly code (experimental)',
defaultsTo: _CLOSURE_DEFAULT)
..addFlag('destructure-named-params',
help: 'Destructure named parameters (requires ES6-enabled runtime)',
defaultsTo: _DESTRUCTURE_NAMED_PARAMS_DEFAULT)
..addFlag('force-compile',
abbr: 'f', help: 'Compile code with static errors', defaultsTo: false)
..addOption('log', abbr: 'l', help: 'Logging level (defaults to warning)')
Expand Down