Skip to content

Commit

Permalink
remove support for const
Browse files Browse the repository at this point in the history
As this is not part of ES5.
  • Loading branch information
alexlamsl committed May 11, 2017
1 parent aae7d49 commit 5284327
Show file tree
Hide file tree
Showing 19 changed files with 34 additions and 484 deletions.
16 changes: 4 additions & 12 deletions lib/ast.js
Original file line number Diff line number Diff line change
Expand Up @@ -495,10 +495,10 @@ var AST_Finally = DEFNODE("Finally", null, {
$documentation: "A `finally` node; only makes sense as part of a `try` statement"
}, AST_Block);

/* -----[ VAR/CONST ]----- */
/* -----[ VAR ]----- */

var AST_Definitions = DEFNODE("Definitions", "definitions", {
$documentation: "Base class for `var` or `const` nodes (variable declarations/initializations)",
$documentation: "Base class for `var` nodes (variable declarations/initializations)",
$propdoc: {
definitions: "[AST_VarDef*] array of variable definitions"
},
Expand All @@ -516,14 +516,10 @@ var AST_Var = DEFNODE("Var", null, {
$documentation: "A `var` statement"
}, AST_Definitions);

var AST_Const = DEFNODE("Const", null, {
$documentation: "A `const` statement"
}, AST_Definitions);

var AST_VarDef = DEFNODE("VarDef", "name value", {
$documentation: "A variable declaration; only appears in a AST_Definitions node",
$propdoc: {
name: "[AST_SymbolVar|AST_SymbolConst] name of the variable",
name: "[AST_SymbolVar] name of the variable",
value: "[AST_Node?] initializer, or null of there's no initializer"
},
_walk: function(visitor) {
Expand Down Expand Up @@ -728,17 +724,13 @@ var AST_SymbolAccessor = DEFNODE("SymbolAccessor", null, {
}, AST_Symbol);

var AST_SymbolDeclaration = DEFNODE("SymbolDeclaration", "init", {
$documentation: "A declaration symbol (symbol in var/const, function name or argument, symbol in catch)",
$documentation: "A declaration symbol (symbol in var, function name or argument, symbol in catch)",
}, AST_Symbol);

var AST_SymbolVar = DEFNODE("SymbolVar", null, {
$documentation: "Symbol defining a variable",
}, AST_SymbolDeclaration);

var AST_SymbolConst = DEFNODE("SymbolConst", null, {
$documentation: "A constant declaration"
}, AST_SymbolDeclaration);

var AST_SymbolFunarg = DEFNODE("SymbolFunarg", null, {
$documentation: "Symbol naming a function argument",
}, AST_SymbolVar);
Expand Down
5 changes: 2 additions & 3 deletions lib/compress.js
Original file line number Diff line number Diff line change
Expand Up @@ -475,8 +475,7 @@ merge(Compressor.prototype, {
if (def.fixed === false) return false;
if (def.fixed != null && (!value || def.references.length > 0)) return false;
return !def.orig.some(function(sym) {
return sym instanceof AST_SymbolConst
|| sym instanceof AST_SymbolDefun
return sym instanceof AST_SymbolDefun
|| sym instanceof AST_SymbolLambda;
});
}
Expand All @@ -491,7 +490,7 @@ merge(Compressor.prototype, {

function reset_def(def) {
def.escaped = false;
if (!def.global || def.orig[0] instanceof AST_SymbolConst || compressor.toplevel(def)) {
if (!def.global || compressor.toplevel(def)) {
def.fixed = undefined;
} else {
def.fixed = false;
Expand Down
6 changes: 3 additions & 3 deletions lib/mozilla-ast.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@
});
},
VariableDeclaration: function(M) {
return new (M.kind === "const" ? AST_Const : AST_Var)({
return new AST_Var({
start : my_start_token(M),
end : my_end_token(M),
definitions : M.declarations.map(from_moz)
Expand Down Expand Up @@ -208,7 +208,7 @@
Identifier: function(M) {
var p = FROM_MOZ_STACK[FROM_MOZ_STACK.length - 2];
return new ( p.type == "LabeledStatement" ? AST_Label
: p.type == "VariableDeclarator" && p.id === M ? (p.kind == "const" ? AST_SymbolConst : AST_SymbolVar)
: p.type == "VariableDeclarator" && p.id === M ? AST_SymbolVar
: p.type == "FunctionExpression" ? (p.id === M ? AST_SymbolLambda : AST_SymbolFunarg)
: p.type == "FunctionDeclaration" ? (p.id === M ? AST_SymbolDefun : AST_SymbolFunarg)
: p.type == "CatchClause" ? AST_SymbolCatch
Expand Down Expand Up @@ -331,7 +331,7 @@
def_to_moz(AST_Definitions, function To_Moz_VariableDeclaration(M) {
return {
type: "VariableDeclaration",
kind: M instanceof AST_Const ? "const" : "var",
kind: "var",
declarations: M.definitions.map(to_moz)
};
});
Expand Down
3 changes: 0 additions & 3 deletions lib/output.js
Original file line number Diff line number Diff line change
Expand Up @@ -1033,9 +1033,6 @@ function OutputStream(options) {
DEFPRINT(AST_Var, function(self, output){
self._do_print(output, "var");
});
DEFPRINT(AST_Const, function(self, output){
self._do_print(output, "const");
});

function parenthesize_for_noin(node, output, noin) {
if (!noin) node.print(output);
Expand Down
22 changes: 4 additions & 18 deletions lib/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -916,9 +916,6 @@ function parse($TEXT, options) {
case "var":
return tmp = var_(), semicolon(), tmp;

case "const":
return tmp = const_(), semicolon(), tmp;

case "with":
if (S.input.has_directive("use strict")) {
croak("Strict mode may not include a with statement");
Expand Down Expand Up @@ -1153,16 +1150,13 @@ function parse($TEXT, options) {
});
};

function vardefs(no_in, in_const) {
function vardefs(no_in) {
var a = [];
for (;;) {
a.push(new AST_VarDef({
start : S.token,
name : as_symbol(in_const ? AST_SymbolConst : AST_SymbolVar),
value : is("operator", "=")
? (next(), expression(false, no_in))
: in_const && S.input.has_directive("use strict")
? croak("Missing initializer in const declaration") : null,
name : as_symbol(AST_SymbolVar),
value : is("operator", "=") ? (next(), expression(false, no_in)) : null,
end : prev()
}));
if (!is("punc", ","))
Expand All @@ -1175,15 +1169,7 @@ function parse($TEXT, options) {
var var_ = function(no_in) {
return new AST_Var({
start : prev(),
definitions : vardefs(no_in, false),
end : prev()
});
};

var const_ = function() {
return new AST_Const({
start : prev(),
definitions : vardefs(false, true),
definitions : vardefs(no_in),
end : prev()
});
};
Expand Down
7 changes: 2 additions & 5 deletions lib/scope.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,7 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options){
// later.
(node.scope = defun.parent_scope).def_function(node);
}
else if (node instanceof AST_SymbolVar
|| node instanceof AST_SymbolConst) {
else if (node instanceof AST_SymbolVar) {
defun.def_variable(node);
if (defun !== scope) {
node.mark_enclosed(options);
Expand Down Expand Up @@ -268,7 +267,7 @@ AST_Scope.DEFMETHOD("init_scope_vars", function(parent_scope){
AST_Lambda.DEFMETHOD("init_scope_vars", function(){
AST_Scope.prototype.init_scope_vars.apply(this, arguments);
this.uses_arguments = false;
this.def_variable(new AST_SymbolConst({
this.def_variable(new AST_SymbolFunarg({
name: "arguments",
start: this.start,
end: this.end
Expand Down Expand Up @@ -491,8 +490,6 @@ AST_Toplevel.DEFMETHOD("compute_char_frequency", function(options){
}
else if (node instanceof AST_Var)
base54.consider("var");
else if (node instanceof AST_Const)
base54.consider("const");
else if (node instanceof AST_Lambda)
base54.consider("function");
else if (node instanceof AST_For)
Expand Down
10 changes: 5 additions & 5 deletions test/compress/collapse_vars.js
Original file line number Diff line number Diff line change
Expand Up @@ -583,8 +583,8 @@ collapse_vars_assignment: {
return a = a;
}
function f1(c) {
const a = 3 / c;
const b = 1 - a;
var a = 3 / c;
var b = 1 - a;
return b;
}
function f2(c) {
Expand Down Expand Up @@ -724,10 +724,10 @@ collapse_vars_misc1: {
return t;
}
function f1(x) { var y = 5 - x; return y; }
function f2(x) { const z = foo(), y = z / (5 - x); return y; }
function f2(x) { var z = foo(), y = z / (5 - x); return y; }
function f3(x) { var z = foo(), y = (5 - x) / z; return y; }
function f4(x) { var z = foo(), y = (5 - u) / z; return y; }
function f5(x) { const z = foo(), y = (5 - window.x) / z; return y; }
function f5(x) { var z = foo(), y = (5 - window.x) / z; return y; }
function f6() { var b = window.a * window.z; return b && zap(); }
function f7() { var b = window.a * window.z; return b + b; }
function f8() { var b = window.a * window.z; var c = b + 5; return b + c; }
Expand All @@ -744,7 +744,7 @@ collapse_vars_misc1: {
function f2(x) { return foo() / (5 - x) }
function f3(x) { return (5 - x) / foo() }
function f4(x) { var z = foo(); return (5 - u) / z }
function f5(x) { const z = foo(); return (5 - window.x) / z }
function f5(x) { var z = foo(); return (5 - window.x) / z }
function f6() { return window.a * window.z && zap() }
function f7() { var b = window.a * window.z; return b + b }
function f8() { var b = window.a * window.z; return b + (b + 5) }
Expand Down
166 changes: 0 additions & 166 deletions test/compress/const.js

This file was deleted.

Loading

0 comments on commit 5284327

Please sign in to comment.