more utility simplifications
This commit is contained in:
parent
832e1d8cb8
commit
1e1146d61d
12
lib/lexer.js
12
lib/lexer.js
|
@ -1,6 +1,6 @@
|
||||||
(function(){
|
(function(){
|
||||||
var ACCESSORS, ASSIGNMENT, CALLABLE, CODE, COFFEE_ALIASES, COFFEE_KEYWORDS, COMMENT, COMMENT_CLEANER, CONVERSIONS, HALF_ASSIGNMENTS, HEREDOC, HEREDOC_INDENT, IDENTIFIER, INTERPOLATION, JS_CLEANER, JS_FORBIDDEN, JS_KEYWORDS, KEYWORDS, LAST_DENT, LAST_DENTS, LINE_BREAK, Lexer, MULTILINER, MULTI_DENT, NOT_REGEX, NO_NEWLINE, NUMBER, OPERATOR, REGEX_ESCAPE, REGEX_FLAGS, REGEX_INTERPOLATION, REGEX_START, RESERVED, Rewriter, STRING_NEWLINES, WHITESPACE, _a, _b, _c, _d, balanced_string, compact, count, helpers, include, k, starts, u;
|
var ACCESSORS, ASSIGNMENT, CALLABLE, CODE, COFFEE_ALIASES, COFFEE_KEYWORDS, COMMENT, COMMENT_CLEANER, CONVERSIONS, HALF_ASSIGNMENTS, HEREDOC, HEREDOC_INDENT, IDENTIFIER, INTERPOLATION, JS_CLEANER, JS_FORBIDDEN, JS_KEYWORDS, KEYWORDS, LAST_DENT, LAST_DENTS, LINE_BREAK, Lexer, MULTILINER, MULTI_DENT, NOT_REGEX, NO_NEWLINE, NUMBER, OPERATOR, REGEX_ESCAPE, REGEX_FLAGS, REGEX_INTERPOLATION, REGEX_START, RESERVED, Rewriter, STRING_NEWLINES, WHITESPACE, balanced_string, compact, count, helpers, include, starts;
|
||||||
var __slice = Array.prototype.slice, __hasProp = Object.prototype.hasOwnProperty;
|
var __slice = Array.prototype.slice;
|
||||||
// The CoffeeScript Lexer. Uses a series of token-matching regexes to attempt
|
// The CoffeeScript Lexer. Uses a series of token-matching regexes to attempt
|
||||||
// matches against the beginning of the source code. When a match is found,
|
// matches against the beginning of the source code. When a match is found,
|
||||||
// a token is produced, we consume the match, and start again. Tokens are in the
|
// a token is produced, we consume the match, and start again. Tokens are in the
|
||||||
|
@ -610,13 +610,7 @@
|
||||||
// The list of keywords that are reserved by JavaScript, but not used, or are
|
// The list of keywords that are reserved by JavaScript, but not used, or are
|
||||||
// used by CoffeeScript internally. We throw an error when these are encountered,
|
// used by CoffeeScript internally. We throw an error when these are encountered,
|
||||||
// to avoid having a JavaScript error at runtime.
|
// to avoid having a JavaScript error at runtime.
|
||||||
RESERVED = ["case", "default", "do", "function", "var", "void", "with", "const", "let", "debugger", "enum", "export", "import", "native"].concat((function() {
|
RESERVED = ["case", "default", "do", "function", "var", "void", "with", "const", "let", "debugger", "enum", "export", "import", "native"];
|
||||||
_c = []; _d = (u = require('./utilities')).utilities.functions;
|
|
||||||
for (k in _d) { if (__hasProp.call(_d, k)) {
|
|
||||||
_c.push("__" + k);
|
|
||||||
}}
|
|
||||||
return _c;
|
|
||||||
}).call(this));
|
|
||||||
// The superset of both JavaScript keywords and reserved words, none of which may
|
// The superset of both JavaScript keywords and reserved words, none of which may
|
||||||
// be used as identifiers or properties.
|
// be used as identifiers or properties.
|
||||||
JS_FORBIDDEN = JS_KEYWORDS.concat(RESERVED);
|
JS_FORBIDDEN = JS_KEYWORDS.concat(RESERVED);
|
||||||
|
|
15
lib/scope.js
15
lib/scope.js
|
@ -112,17 +112,13 @@
|
||||||
};
|
};
|
||||||
// Formats an javascript object containing the utility methods required
|
// Formats an javascript object containing the utility methods required
|
||||||
// in the scope
|
// in the scope
|
||||||
Scope.prototype.included_utilities = function included_utilities(tab) {
|
Scope.prototype.included_utilities = function included_utilities() {
|
||||||
var _a, _b, _c, key;
|
var _a, _b, key;
|
||||||
if ((typeof (_c = this.utilities) !== "undefined" && _c !== null)) {
|
|
||||||
_a = []; _b = this.utilities;
|
_a = []; _b = this.utilities;
|
||||||
for (key in _b) { if (__hasProp.call(_b, key)) {
|
for (key in _b) { if (__hasProp.call(_b, key)) {
|
||||||
_a.push(utilities.format(key, tab));
|
_a.push("__" + key + " = " + (utilities.functions[key]));
|
||||||
}}
|
}}
|
||||||
return _a;
|
return _a;
|
||||||
} else {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
// Does this scope reference any variables that need to be declared in the
|
// Does this scope reference any variables that need to be declared in the
|
||||||
// given function body?
|
// given function body?
|
||||||
|
@ -134,8 +130,7 @@
|
||||||
// Does this scope reference any assignments that need to be declared at the
|
// Does this scope reference any assignments that need to be declared at the
|
||||||
// top of the given function body?
|
// top of the given function body?
|
||||||
Scope.prototype.has_assignments = function has_assignments(body) {
|
Scope.prototype.has_assignments = function has_assignments(body) {
|
||||||
var _a;
|
return body === this.expressions && (this.utilities || this.any(function(k, val) {
|
||||||
return body === this.expressions && ((typeof (_a = this.utilities) !== "undefined" && _a !== null) || this.any(function(k, val) {
|
|
||||||
return val.assigned;
|
return val.assigned;
|
||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
|
@ -168,7 +163,7 @@
|
||||||
};
|
};
|
||||||
// Compile the JavaScript for all of the variable assignments in this scope.
|
// Compile the JavaScript for all of the variable assignments in this scope.
|
||||||
Scope.prototype.compiled_assignments = function compiled_assignments(tab) {
|
Scope.prototype.compiled_assignments = function compiled_assignments(tab) {
|
||||||
return this.assigned_variables().concat(this.included_utilities(tab)).join(', ');
|
return this.assigned_variables().concat(this.included_utilities()).join(', ');
|
||||||
};
|
};
|
||||||
return Scope;
|
return Scope;
|
||||||
}).call(this);
|
}).call(this);
|
||||||
|
|
|
@ -1,12 +1,8 @@
|
||||||
(function(){
|
(function(){
|
||||||
var utils;
|
|
||||||
if (!((typeof process !== "undefined" && process !== null))) {
|
if (!((typeof process !== "undefined" && process !== null))) {
|
||||||
this.exports = this;
|
this.exports = this;
|
||||||
}
|
}
|
||||||
exports.utilities = (utils = {
|
exports.utilities = {
|
||||||
format: function format(key, tab) {
|
|
||||||
return "__" + key + " = " + (utils.functions[key].replace(/\n/g, "\n" + tab) || 'undefined');
|
|
||||||
},
|
|
||||||
dependencies: {
|
dependencies: {
|
||||||
bind: ['slice']
|
bind: ['slice']
|
||||||
},
|
},
|
||||||
|
@ -17,5 +13,5 @@
|
||||||
hasProp: 'Object.prototype.hasOwnProperty',
|
hasProp: 'Object.prototype.hasOwnProperty',
|
||||||
slice: 'Array.prototype.slice'
|
slice: 'Array.prototype.slice'
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
})();
|
})();
|
||||||
|
|
|
@ -463,8 +463,7 @@ KEYWORDS: JS_KEYWORDS.concat COFFEE_KEYWORDS
|
||||||
# to avoid having a JavaScript error at runtime.
|
# to avoid having a JavaScript error at runtime.
|
||||||
RESERVED: [
|
RESERVED: [
|
||||||
"case", "default", "do", "function", "var", "void", "with"
|
"case", "default", "do", "function", "var", "void", "with"
|
||||||
"const", "let", "debugger", "enum", "export", "import", "native",
|
"const", "let", "debugger", "enum", "export", "import", "native"
|
||||||
("__$k" for k of (u: require './utilities').utilities.functions)...
|
|
||||||
]
|
]
|
||||||
|
|
||||||
# The superset of both JavaScript keywords and reserved words, none of which may
|
# The superset of both JavaScript keywords and reserved words, none of which may
|
||||||
|
|
|
@ -74,10 +74,8 @@ exports.Scope: class Scope
|
||||||
|
|
||||||
# Formats an javascript object containing the utility methods required
|
# Formats an javascript object containing the utility methods required
|
||||||
# in the scope
|
# in the scope
|
||||||
included_utilities: (tab) ->
|
included_utilities: ->
|
||||||
if @utilities?
|
"__$key = ${utilities.functions[key]}" for key of @utilities
|
||||||
utilities.format(key, tab) for key of @utilities
|
|
||||||
else []
|
|
||||||
|
|
||||||
# Does this scope reference any variables that need to be declared in the
|
# Does this scope reference any variables that need to be declared in the
|
||||||
# given function body?
|
# given function body?
|
||||||
|
@ -87,7 +85,7 @@ exports.Scope: class Scope
|
||||||
# Does this scope reference any assignments that need to be declared at the
|
# Does this scope reference any assignments that need to be declared at the
|
||||||
# top of the given function body?
|
# top of the given function body?
|
||||||
has_assignments: (body) ->
|
has_assignments: (body) ->
|
||||||
body is @expressions and (@utilities? or @any (k, val) -> val.assigned)
|
body is @expressions and (@utilities or @any (k, val) -> val.assigned)
|
||||||
|
|
||||||
# Return the list of variables first declared in this scope.
|
# Return the list of variables first declared in this scope.
|
||||||
declared_variables: ->
|
declared_variables: ->
|
||||||
|
@ -104,4 +102,4 @@ exports.Scope: class Scope
|
||||||
|
|
||||||
# Compile the JavaScript for all of the variable assignments in this scope.
|
# Compile the JavaScript for all of the variable assignments in this scope.
|
||||||
compiled_assignments: (tab) ->
|
compiled_assignments: (tab) ->
|
||||||
[@assigned_variables()..., @included_utilities(tab)...].join ', '
|
[@assigned_variables()..., @included_utilities()...].join ', '
|
||||||
|
|
|
@ -1,9 +1,6 @@
|
||||||
this.exports: this unless process?
|
this.exports: this unless process?
|
||||||
|
|
||||||
exports.utilities: utils: {
|
exports.utilities: {
|
||||||
|
|
||||||
format: (key, tab) ->
|
|
||||||
"__$key = ${utils.functions[key].replace(/\n/g, "\n$tab") or 'undefined'}"
|
|
||||||
|
|
||||||
dependencies: {
|
dependencies: {
|
||||||
bind: ['slice']
|
bind: ['slice']
|
||||||
|
|
Loading…
Reference in New Issue