fix #1508: jshint is broken in build
This commit is contained in:
parent
e3d14ab620
commit
c5378b54e1
6 changed files with 334 additions and 171 deletions
|
|
@ -603,7 +603,9 @@ function namespace(ns) {
|
||||||
text = text
|
text = text
|
||||||
.toString()
|
.toString()
|
||||||
.replace('var ACE_NAMESPACE = "";', 'var ACE_NAMESPACE = "' + ns +'";')
|
.replace('var ACE_NAMESPACE = "";', 'var ACE_NAMESPACE = "' + ns +'";')
|
||||||
.replace(/\bdefine\(/g, ns + ".define(");
|
.replace(/(.define)|\bdefine\(/g, function(_, a) {
|
||||||
|
return a || ns + ".define("
|
||||||
|
});
|
||||||
|
|
||||||
return text;
|
return text;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/** vim: et:ts=4:sw=4:sts=4
|
/** vim: et:ts=4:sw=4:sts=4
|
||||||
* @license RequireJS 2.1.6 Copyright (c) 2010-2012, The Dojo Foundation All Rights Reserved.
|
* @license RequireJS 2.1.7 Copyright (c) 2010-2012, The Dojo Foundation All Rights Reserved.
|
||||||
* Available via the MIT or new BSD license.
|
* Available via the MIT or new BSD license.
|
||||||
* see: http://github.com/jrburke/requirejs for details
|
* see: http://github.com/jrburke/requirejs for details
|
||||||
*/
|
*/
|
||||||
|
|
@ -12,7 +12,7 @@ var requirejs, require, define;
|
||||||
(function (global) {
|
(function (global) {
|
||||||
var req, s, head, baseElement, dataMain, src,
|
var req, s, head, baseElement, dataMain, src,
|
||||||
interactiveScript, currentlyAddingScript, mainScript, subPath,
|
interactiveScript, currentlyAddingScript, mainScript, subPath,
|
||||||
version = '2.1.6',
|
version = '2.1.7',
|
||||||
commentRegExp = /(\/\*([\s\S]*?)\*\/|([^:]|^)\/\/(.*)$)/mg,
|
commentRegExp = /(\/\*([\s\S]*?)\*\/|([^:]|^)\/\/(.*)$)/mg,
|
||||||
cjsRequireRegExp = /[^.]\s*require\s*\(\s*["']([^'"\s]+)["']\s*\)/g,
|
cjsRequireRegExp = /[^.]\s*require\s*\(\s*["']([^'"\s]+)["']\s*\)/g,
|
||||||
jsSuffixRegExp = /\.js$/,
|
jsSuffixRegExp = /\.js$/,
|
||||||
|
|
@ -1794,6 +1794,19 @@ var requirejs, require, define;
|
||||||
*/
|
*/
|
||||||
req.onError = defaultOnError;
|
req.onError = defaultOnError;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates the node for the load command. Only used in browser envs.
|
||||||
|
*/
|
||||||
|
req.createNode = function (config, moduleName, url) {
|
||||||
|
var node = config.xhtml ?
|
||||||
|
document.createElementNS('http://www.w3.org/1999/xhtml', 'html:script') :
|
||||||
|
document.createElement('script');
|
||||||
|
node.type = config.scriptType || 'text/javascript';
|
||||||
|
node.charset = 'utf-8';
|
||||||
|
node.async = true;
|
||||||
|
return node;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Does the request to load a module for the browser case.
|
* Does the request to load a module for the browser case.
|
||||||
* Make this a separate function to allow other environments
|
* Make this a separate function to allow other environments
|
||||||
|
|
@ -1808,12 +1821,7 @@ var requirejs, require, define;
|
||||||
node;
|
node;
|
||||||
if (isBrowser) {
|
if (isBrowser) {
|
||||||
//In the browser so use a script tag
|
//In the browser so use a script tag
|
||||||
node = config.xhtml ?
|
node = req.createNode(config, moduleName, url);
|
||||||
document.createElementNS('http://www.w3.org/1999/xhtml', 'html:script') :
|
|
||||||
document.createElement('script');
|
|
||||||
node.type = config.scriptType || 'text/javascript';
|
|
||||||
node.charset = 'utf-8';
|
|
||||||
node.async = true;
|
|
||||||
|
|
||||||
node.setAttribute('data-requirecontext', context.contextName);
|
node.setAttribute('data-requirecontext', context.contextName);
|
||||||
node.setAttribute('data-requiremodule', moduleName);
|
node.setAttribute('data-requiremodule', moduleName);
|
||||||
|
|
|
||||||
|
|
@ -197,7 +197,7 @@ require.alias = function (from, to) {
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
|
||||||
require.define("path",function(require,module,exports,__dirname,__filename,process,global) {
|
require.def("path",function(req,module,exports,__dirname,__filename,process,global) {
|
||||||
function filter (xs, fn) {
|
function filter (xs, fn) {
|
||||||
var res = [];
|
var res = [];
|
||||||
for (var i = 0; i < xs.length; i++) {
|
for (var i = 0; i < xs.length; i++) {
|
||||||
|
|
@ -336,7 +336,7 @@ exports.extname = function(path) {
|
||||||
//@ sourceURL=path
|
//@ sourceURL=path
|
||||||
});
|
});
|
||||||
|
|
||||||
require.define("__browserify_process",function(require,module,exports,__dirname,__filename,process,global) {
|
require.def("__browserify_process",function(req,module,exports,__dirname,__filename,process,global) {
|
||||||
var process = module.exports = {};
|
var process = module.exports = {};
|
||||||
|
|
||||||
process.nextTick = (function () {
|
process.nextTick = (function () {
|
||||||
|
|
@ -379,7 +379,7 @@ process.env = {};
|
||||||
process.argv = [];
|
process.argv = [];
|
||||||
|
|
||||||
process.binding = function (name) {
|
process.binding = function (name) {
|
||||||
if (name === 'evals') return (require)('vm')
|
if (name === 'evals') return (req)('vm')
|
||||||
else throw new Error('No such module. (Possibly not yet loaded)')
|
else throw new Error('No such module. (Possibly not yet loaded)')
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -388,7 +388,7 @@ process.binding = function (name) {
|
||||||
var path;
|
var path;
|
||||||
process.cwd = function () { return cwd };
|
process.cwd = function () { return cwd };
|
||||||
process.chdir = function (dir) {
|
process.chdir = function (dir) {
|
||||||
if (!path) path = require('path');
|
if (!path) path = req('path');
|
||||||
cwd = path.resolve(dir, cwd);
|
cwd = path.resolve(dir, cwd);
|
||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
|
|
@ -396,12 +396,12 @@ process.binding = function (name) {
|
||||||
//@ sourceURL=__browserify_process
|
//@ sourceURL=__browserify_process
|
||||||
});
|
});
|
||||||
|
|
||||||
require.define("/node_modules/underscore/package.json",function(require,module,exports,__dirname,__filename,process,global) {
|
require.def("/node_modules/underscore/package.json",function(req,module,exports,__dirname,__filename,process,global) {
|
||||||
module.exports = {"main":"underscore.js"}
|
module.exports = {"main":"underscore.js"}
|
||||||
//@ sourceURL=/node_modules/underscore/package.json
|
//@ sourceURL=/node_modules/underscore/package.json
|
||||||
});
|
});
|
||||||
|
|
||||||
require.define("/node_modules/underscore/underscore.js",function(require,module,exports,__dirname,__filename,process,global) {
|
require.def("/node_modules/underscore/underscore.js",function(req,module,exports,__dirname,__filename,process,global) {
|
||||||
// Underscore.js 1.4.0
|
// Underscore.js 1.4.0
|
||||||
// http://underscorejs.org
|
// http://underscorejs.org
|
||||||
// (c) 2009-2012 Jeremy Ashkenas, DocumentCloud Inc.
|
// (c) 2009-2012 Jeremy Ashkenas, DocumentCloud Inc.
|
||||||
|
|
@ -1592,7 +1592,7 @@ require.define("/node_modules/underscore/underscore.js",function(require,module,
|
||||||
//@ sourceURL=/node_modules/underscore/underscore.js
|
//@ sourceURL=/node_modules/underscore/underscore.js
|
||||||
});
|
});
|
||||||
|
|
||||||
require.define("events",function(require,module,exports,__dirname,__filename,process,global) {
|
require.def("events",function(req,module,exports,__dirname,__filename,process,global) {
|
||||||
if (!process.EventEmitter) process.EventEmitter = function () {};
|
if (!process.EventEmitter) process.EventEmitter = function () {};
|
||||||
|
|
||||||
var EventEmitter = exports.EventEmitter = process.EventEmitter;
|
var EventEmitter = exports.EventEmitter = process.EventEmitter;
|
||||||
|
|
@ -1609,7 +1609,7 @@ var isArray = typeof Array.isArray === 'function'
|
||||||
//
|
//
|
||||||
// Obviously not all Emitters should be limited to 10. This function allows
|
// Obviously not all Emitters should be limited to 10. This function allows
|
||||||
// that to be increased. Set to zero for unlimited.
|
// that to be increased. Set to zero for unlimited.
|
||||||
var defaultMaxListeners = 10;
|
var defaultMaxListeners = 200;
|
||||||
EventEmitter.prototype.setMaxListeners = function(n) {
|
EventEmitter.prototype.setMaxListeners = function(n) {
|
||||||
if (!this._events) this._events = {};
|
if (!this._events) this._events = {};
|
||||||
this._events.maxListeners = n;
|
this._events.maxListeners = n;
|
||||||
|
|
@ -1768,7 +1768,7 @@ EventEmitter.prototype.listeners = function(type) {
|
||||||
//@ sourceURL=events
|
//@ sourceURL=events
|
||||||
});
|
});
|
||||||
|
|
||||||
require.define("/src/shared/vars.js",function(require,module,exports,__dirname,__filename,process,global) {
|
require.def("/src/shared/vars.js",function(req,module,exports,__dirname,__filename,process,global) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
// Identifiers provided by the ECMAScript standard.
|
// Identifiers provided by the ECMAScript standard.
|
||||||
|
|
@ -2160,10 +2160,10 @@ exports.yui = {
|
||||||
//@ sourceURL=/src/shared/vars.js
|
//@ sourceURL=/src/shared/vars.js
|
||||||
});
|
});
|
||||||
|
|
||||||
require.define("/src/shared/messages.js",function(require,module,exports,__dirname,__filename,process,global) {
|
require.def("/src/shared/messages.js",function(req,module,exports,__dirname,__filename,process,global) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var _ = require("underscore");
|
var _ = req("underscore");
|
||||||
|
|
||||||
var errors = {
|
var errors = {
|
||||||
// JSHint options
|
// JSHint options
|
||||||
|
|
@ -2371,17 +2371,17 @@ _.each(info, function (desc, code) {
|
||||||
//@ sourceURL=/src/shared/messages.js
|
//@ sourceURL=/src/shared/messages.js
|
||||||
});
|
});
|
||||||
|
|
||||||
require.define("/src/stable/lex.js",function(require,module,exports,__dirname,__filename,process,global) {
|
require.def("/src/stable/lex.js",function(req,module,exports,__dirname,__filename,process,global) {
|
||||||
/*
|
/*
|
||||||
* Lexical analysis and token construction.
|
* Lexical analysis and token construction.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var _ = require("underscore");
|
var _ = req("underscore");
|
||||||
var events = require("events");
|
var events = req("events");
|
||||||
var reg = require("./reg.js");
|
var reg = req("./reg.js");
|
||||||
var state = require("./state.js").state;
|
var state = req("./state.js").state;
|
||||||
|
|
||||||
// Some of these token types are from JavaScript Parser API
|
// Some of these token types are from JavaScript Parser API
|
||||||
// while others are specific to JSHint parser.
|
// while others are specific to JSHint parser.
|
||||||
|
|
@ -3987,7 +3987,7 @@ exports.Lexer = Lexer;
|
||||||
//@ sourceURL=/src/stable/lex.js
|
//@ sourceURL=/src/stable/lex.js
|
||||||
});
|
});
|
||||||
|
|
||||||
require.define("/src/stable/reg.js",function(require,module,exports,__dirname,__filename,process,global) {
|
require.def("/src/stable/reg.js",function(req,module,exports,__dirname,__filename,process,global) {
|
||||||
/*
|
/*
|
||||||
* Regular expressions. Some of these are stupidly long.
|
* Regular expressions. Some of these are stupidly long.
|
||||||
*/
|
*/
|
||||||
|
|
@ -4025,7 +4025,7 @@ exports.fallsThrough = /^\s*\/\*\s*falls\sthrough\s*\*\/\s*$/;
|
||||||
//@ sourceURL=/src/stable/reg.js
|
//@ sourceURL=/src/stable/reg.js
|
||||||
});
|
});
|
||||||
|
|
||||||
require.define("/src/stable/state.js",function(require,module,exports,__dirname,__filename,process,global) {
|
require.def("/src/stable/state.js",function(req,module,exports,__dirname,__filename,process,global) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var state = {
|
var state = {
|
||||||
|
|
@ -4051,7 +4051,7 @@ exports.state = state;
|
||||||
//@ sourceURL=/src/stable/state.js
|
//@ sourceURL=/src/stable/state.js
|
||||||
});
|
});
|
||||||
|
|
||||||
require.define("/src/stable/style.js",function(require,module,exports,__dirname,__filename,process,global) {
|
require.def("/src/stable/style.js",function(req,module,exports,__dirname,__filename,process,global) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
exports.register = function (linter) {
|
exports.register = function (linter) {
|
||||||
|
|
@ -4226,7 +4226,7 @@ exports.register = function (linter) {
|
||||||
//@ sourceURL=/src/stable/style.js
|
//@ sourceURL=/src/stable/style.js
|
||||||
});
|
});
|
||||||
|
|
||||||
require.define("/src/stable/jshint.js",function(require,module,exports,__dirname,__filename,process,global) {
|
require.def("/src/stable/jshint.js",function(req,module,exports,__dirname,__filename,process,global) {
|
||||||
/*!
|
/*!
|
||||||
* JSHint, by JSHint Community.
|
* JSHint, by JSHint Community.
|
||||||
*
|
*
|
||||||
|
|
@ -4259,14 +4259,14 @@ require.define("/src/stable/jshint.js",function(require,module,exports,__dirname
|
||||||
|
|
||||||
/*jshint quotmark:double */
|
/*jshint quotmark:double */
|
||||||
|
|
||||||
var _ = require("underscore");
|
var _ = req("underscore");
|
||||||
var events = require("events");
|
var events = req("events");
|
||||||
var vars = require("../shared/vars.js");
|
var vars = req("../shared/vars.js");
|
||||||
var messages = require("../shared/messages.js");
|
var messages = req("../shared/messages.js");
|
||||||
var Lexer = require("./lex.js").Lexer;
|
var Lexer = req("./lex.js").Lexer;
|
||||||
var reg = require("./reg.js");
|
var reg = req("./reg.js");
|
||||||
var state = require("./state.js").state;
|
var state = req("./state.js").state;
|
||||||
var style = require("./style.js");
|
var style = req("./style.js");
|
||||||
|
|
||||||
// We build the application inside a function so that we produce only a single
|
// We build the application inside a function so that we produce only a single
|
||||||
// global variable. That function will be invoked immediately, and its return
|
// global variable. That function will be invoked immediately, and its return
|
||||||
|
|
@ -7888,8 +7888,7 @@ if (typeof exports === "object" && exports) {
|
||||||
|
|
||||||
//@ sourceURL=/src/stable/jshint.js
|
//@ sourceURL=/src/stable/jshint.js
|
||||||
});
|
});
|
||||||
require("/src/stable/jshint.js");
|
req("/src/stable/jshint.js");
|
||||||
|
|
||||||
var jsHint = require("/src/stable/jshint.js");
|
function req() {return require.apply(this, arguments)}module.exports = req("/src/stable/jshint.js");
|
||||||
return function(require, exports, module) {module.exports = jsHint;}
|
})
|
||||||
}())
|
|
||||||
|
|
@ -2,41 +2,11 @@ define(function(require, exports, module) {
|
||||||
/*global exports:true module:true require:true define:true global:true */
|
/*global exports:true module:true require:true define:true global:true */
|
||||||
|
|
||||||
(function (root, name, factory) {
|
(function (root, name, factory) {
|
||||||
'use strict';
|
factory(exports)
|
||||||
|
|
||||||
var freeExports = typeof exports === 'object' && exports
|
|
||||||
// While CommonJS defines `module` as an object, component define it as a
|
|
||||||
// function
|
|
||||||
, freeModule = (typeof module === 'object' || typeof module === 'function') &&
|
|
||||||
module && module.exports === freeExports && module;
|
|
||||||
|
|
||||||
// Detect free variable `global`, from Node.js or Browserified code, and use
|
|
||||||
// it as `root`
|
|
||||||
var freeGlobal = typeof global === 'object' && global;
|
|
||||||
if (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal)
|
|
||||||
root = freeGlobal;
|
|
||||||
|
|
||||||
// Some AMD build optimizers, like r.js, check for specific condition
|
|
||||||
// patterns like the following:
|
|
||||||
if (typeof define === 'function' && define.amd) {
|
|
||||||
define(['exports'], factory);
|
|
||||||
}
|
|
||||||
// check for `exports` after `define` in case a build optimizer adds an
|
|
||||||
// `exports` object
|
|
||||||
else if (freeExports && !freeExports.nodeType) {
|
|
||||||
// in Node.js or RingoJS v0.8.0+
|
|
||||||
if (freeModule) factory(freeModule.exports);
|
|
||||||
// in Narwhal or RingoJS v0.7.0-
|
|
||||||
else factory(freeExports);
|
|
||||||
}
|
|
||||||
// in a browser or Rhino
|
|
||||||
else {
|
|
||||||
factory((root[name] = {}));
|
|
||||||
}
|
|
||||||
}(this, 'luaparse', function (exports) {
|
}(this, 'luaparse', function (exports) {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
exports.version = '0.0.14';
|
exports.version = '0.1.4';
|
||||||
|
|
||||||
var input, options, length;
|
var input, options, length;
|
||||||
|
|
||||||
|
|
@ -50,6 +20,12 @@ define(function(require, exports, module) {
|
||||||
// Track identifier scopes by adding an isLocal attribute to each
|
// Track identifier scopes by adding an isLocal attribute to each
|
||||||
// identifier-node.
|
// identifier-node.
|
||||||
, scope: false
|
, scope: false
|
||||||
|
// Store location information on each syntax node as
|
||||||
|
// `loc: { start: { line, column }, end: { line, column } }`.
|
||||||
|
, locations: false
|
||||||
|
// Store the start and end character locations on each syntax node as
|
||||||
|
// `range: [start, end]`.
|
||||||
|
, ranges: false
|
||||||
};
|
};
|
||||||
|
|
||||||
// The available tokens expressed as enum flags so they can be checked with
|
// The available tokens expressed as enum flags so they can be checked with
|
||||||
|
|
@ -59,6 +35,12 @@ define(function(require, exports, module) {
|
||||||
, NumericLiteral = 16, Punctuator = 32, BooleanLiteral = 64
|
, NumericLiteral = 16, Punctuator = 32, BooleanLiteral = 64
|
||||||
, NilLiteral = 128, VarargLiteral = 256;
|
, NilLiteral = 128, VarargLiteral = 256;
|
||||||
|
|
||||||
|
exports.tokenTypes = { EOF: EOF, StringLiteral: StringLiteral
|
||||||
|
, Keyword: Keyword, Identifier: Identifier, NumericLiteral: NumericLiteral
|
||||||
|
, Punctuator: Punctuator, BooleanLiteral: BooleanLiteral
|
||||||
|
, NilLiteral: NilLiteral, VarargLiteral: VarargLiteral
|
||||||
|
};
|
||||||
|
|
||||||
// As this parser is a bit different from luas own, the error messages
|
// As this parser is a bit different from luas own, the error messages
|
||||||
// will be different in some situations.
|
// will be different in some situations.
|
||||||
|
|
||||||
|
|
@ -321,8 +303,31 @@ define(function(require, exports, module) {
|
||||||
, argument: argument
|
, argument: argument
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
, comment: function(value, raw) {
|
||||||
|
return {
|
||||||
|
type: 'Comment'
|
||||||
|
, value: value
|
||||||
|
, raw: raw
|
||||||
|
};
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Wrap up the node object.
|
||||||
|
|
||||||
|
function finishNode(node) {
|
||||||
|
// Pop a `Marker` off the location-array and attach its location data.
|
||||||
|
if (trackLocations) {
|
||||||
|
var location = locations.pop();
|
||||||
|
location.complete();
|
||||||
|
if (options.locations) node.loc = location.loc;
|
||||||
|
if (options.ranges) node.range = location.range;
|
||||||
|
}
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Helpers
|
// Helpers
|
||||||
// -------
|
// -------
|
||||||
|
|
||||||
|
|
@ -335,6 +340,16 @@ define(function(require, exports, module) {
|
||||||
return -1;
|
return -1;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Iterate through an array of objects and return the index of an object
|
||||||
|
// with a matching property.
|
||||||
|
|
||||||
|
function indexOfObject(array, property, element) {
|
||||||
|
for (var i = 0, length = array.length; i < length; i++) {
|
||||||
|
if (array[i][property] === element) return i;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
// A sprintf implementation using %index (beginning at 1) to input
|
// A sprintf implementation using %index (beginning at 1) to input
|
||||||
// arguments in the format string.
|
// arguments in the format string.
|
||||||
//
|
//
|
||||||
|
|
@ -363,7 +378,7 @@ define(function(require, exports, module) {
|
||||||
, dest = {}
|
, dest = {}
|
||||||
, src, prop;
|
, src, prop;
|
||||||
|
|
||||||
for (var i = 0, l = args.length; i < l; i++) {
|
for (var i = 0, length = args.length; i < length; i++) {
|
||||||
src = args[i];
|
src = args[i];
|
||||||
for (prop in src) if (src.hasOwnProperty(prop)) {
|
for (prop in src) if (src.hasOwnProperty(prop)) {
|
||||||
dest[prop] = src[prop];
|
dest[prop] = src[prop];
|
||||||
|
|
@ -471,6 +486,7 @@ define(function(require, exports, module) {
|
||||||
|
|
||||||
var index
|
var index
|
||||||
, token
|
, token
|
||||||
|
, previousToken
|
||||||
, lookahead
|
, lookahead
|
||||||
, comments
|
, comments
|
||||||
, tokenStart
|
, tokenStart
|
||||||
|
|
@ -496,14 +512,14 @@ define(function(require, exports, module) {
|
||||||
, range: [index, index]
|
, range: [index, index]
|
||||||
};
|
};
|
||||||
|
|
||||||
var character = input.charCodeAt(index)
|
var charCode = input.charCodeAt(index)
|
||||||
, next = input.charCodeAt(index + 1);
|
, next = input.charCodeAt(index + 1);
|
||||||
|
|
||||||
// Memorize the range index where the token begins.
|
// Memorize the range index where the token begins.
|
||||||
tokenStart = index;
|
tokenStart = index;
|
||||||
if (isIdentifierStart(character)) return scanIdentifierOrKeyword();
|
if (isIdentifierStart(charCode)) return scanIdentifierOrKeyword();
|
||||||
|
|
||||||
switch (character) {
|
switch (charCode) {
|
||||||
case 39: case 34: // '"
|
case 39: case 34: // '"
|
||||||
return scanStringLiteral();
|
return scanStringLiteral();
|
||||||
|
|
||||||
|
|
@ -561,10 +577,10 @@ define(function(require, exports, module) {
|
||||||
|
|
||||||
function skipWhiteSpace() {
|
function skipWhiteSpace() {
|
||||||
while (index < length) {
|
while (index < length) {
|
||||||
var character = input.charCodeAt(index);
|
var charCode = input.charCodeAt(index);
|
||||||
if (isWhiteSpace(character)) {
|
if (isWhiteSpace(charCode)) {
|
||||||
index++;
|
index++;
|
||||||
} else if (isLineTerminator(character)) {
|
} else if (isLineTerminator(charCode)) {
|
||||||
line++;
|
line++;
|
||||||
lineStart = ++index;
|
lineStart = ++index;
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -640,20 +656,20 @@ define(function(require, exports, module) {
|
||||||
var delimiter = input.charCodeAt(index++)
|
var delimiter = input.charCodeAt(index++)
|
||||||
, stringStart = index
|
, stringStart = index
|
||||||
, string = ''
|
, string = ''
|
||||||
, character;
|
, charCode;
|
||||||
|
|
||||||
while (index < length) {
|
while (index < length) {
|
||||||
character = input.charCodeAt(index++);
|
charCode = input.charCodeAt(index++);
|
||||||
if (delimiter === character) break;
|
if (delimiter === charCode) break;
|
||||||
if (92 === character) { // \
|
if (92 === charCode) { // \
|
||||||
string += input.slice(stringStart, index - 1) + readEscapeSequence();
|
string += input.slice(stringStart, index - 1) + readEscapeSequence();
|
||||||
stringStart = index;
|
stringStart = index;
|
||||||
}
|
}
|
||||||
// EOF or `\n` terminates a string literal. If we haven't found the
|
// EOF or `\n` terminates a string literal. If we haven't found the
|
||||||
// ending delimiter by now, raise an exception.
|
// ending delimiter by now, raise an exception.
|
||||||
else if (index >= length || isLineTerminator(character)) {
|
else if (index >= length || isLineTerminator(charCode)) {
|
||||||
string += input.slice(stringStart, index - 1);
|
string += input.slice(stringStart, index - 1);
|
||||||
raise({}, errors.unfinishedString, string + String.fromCharCode(character));
|
raise({}, errors.unfinishedString, string + String.fromCharCode(charCode));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
string += input.slice(stringStart, index - 1);
|
string += input.slice(stringStart, index - 1);
|
||||||
|
|
@ -847,7 +863,9 @@ define(function(require, exports, module) {
|
||||||
var character = input.charAt(index)
|
var character = input.charAt(index)
|
||||||
, content = ''
|
, content = ''
|
||||||
, isLong = false
|
, isLong = false
|
||||||
, commentStart = index;
|
, commentStart = index
|
||||||
|
, lineStartComment = lineStart
|
||||||
|
, lineComment = line;
|
||||||
|
|
||||||
if ('[' === character) {
|
if ('[' === character) {
|
||||||
content = readLongString();
|
content = readLongString();
|
||||||
|
|
@ -861,15 +879,24 @@ define(function(require, exports, module) {
|
||||||
if (isLineTerminator(input.charCodeAt(index))) break;
|
if (isLineTerminator(input.charCodeAt(index))) break;
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
content = input.slice(commentStart, index);
|
if (options.comments) content = input.slice(commentStart, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.comments) {
|
if (options.comments) {
|
||||||
comments.push({
|
var node = ast.comment(content, input.slice(tokenStart, index));
|
||||||
type: 'Comment'
|
|
||||||
, value: content
|
// `Marker`s depend on tokens available in the parser and as comments are
|
||||||
, raw: input.slice(tokenStart, index)
|
// intercepted in the lexer all location data is set manually.
|
||||||
});
|
if (options.locations) {
|
||||||
|
node.loc = {
|
||||||
|
start: { line: lineComment, column: tokenStart - lineStartComment }
|
||||||
|
, end: { line: line, column: index - lineStart }
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if (options.ranges) {
|
||||||
|
node.range = [tokenStart, index];
|
||||||
|
}
|
||||||
|
comments.push(node);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -935,6 +962,7 @@ define(function(require, exports, module) {
|
||||||
// reading in the new lookahead token.
|
// reading in the new lookahead token.
|
||||||
|
|
||||||
function next() {
|
function next() {
|
||||||
|
previousToken = token;
|
||||||
token = lookahead;
|
token = lookahead;
|
||||||
lookahead = lex();
|
lookahead = lex();
|
||||||
}
|
}
|
||||||
|
|
@ -959,31 +987,31 @@ define(function(require, exports, module) {
|
||||||
|
|
||||||
// ### Validation functions
|
// ### Validation functions
|
||||||
|
|
||||||
function isWhiteSpace(character) {
|
function isWhiteSpace(charCode) {
|
||||||
return 9 === character || 32 === character || 0xB === character || 0xC === character;
|
return 9 === charCode || 32 === charCode || 0xB === charCode || 0xC === charCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
function isLineTerminator(character) {
|
function isLineTerminator(charCode) {
|
||||||
return 10 === character || 13 === character;
|
return 10 === charCode || 13 === charCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
function isDecDigit(character) {
|
function isDecDigit(charCode) {
|
||||||
return character >= 48 && character <= 57;
|
return charCode >= 48 && charCode <= 57;
|
||||||
}
|
}
|
||||||
|
|
||||||
function isHexDigit(character) {
|
function isHexDigit(charCode) {
|
||||||
return (character >= 48 && character <= 57) || (character >= 97 && character <= 102) || (character >= 65 && character <= 70);
|
return (charCode >= 48 && charCode <= 57) || (charCode >= 97 && charCode <= 102) || (charCode >= 65 && charCode <= 70);
|
||||||
}
|
}
|
||||||
|
|
||||||
// From [Lua 5.2](http://www.lua.org/manual/5.2/manual.html#8.1) onwards
|
// From [Lua 5.2](http://www.lua.org/manual/5.2/manual.html#8.1) onwards
|
||||||
// identifiers cannot use locale-dependet letters.
|
// identifiers cannot use locale-dependet letters.
|
||||||
|
|
||||||
function isIdentifierStart(character) {
|
function isIdentifierStart(charCode) {
|
||||||
return (character >= 65 && character <= 90) || (character >= 97 && character <= 122) || 95 === character;
|
return (charCode >= 65 && charCode <= 90) || (charCode >= 97 && charCode <= 122) || 95 === charCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
function isIdentifierPart(character) {
|
function isIdentifierPart(charCode) {
|
||||||
return (character >= 65 && character <= 90) || (character >= 97 && character <= 122) || 95 === character || (character >= 48 && character <= 57);
|
return (charCode >= 65 && charCode <= 90) || (charCode >= 97 && charCode <= 122) || 95 === charCode || (charCode >= 48 && charCode <= 57);
|
||||||
}
|
}
|
||||||
|
|
||||||
// [3.1 Lexical Conventions](http://www.lua.org/manual/5.2/manual.html#3.1)
|
// [3.1 Lexical Conventions](http://www.lua.org/manual/5.2/manual.html#3.1)
|
||||||
|
|
@ -1048,11 +1076,7 @@ define(function(require, exports, module) {
|
||||||
// The current scope index
|
// The current scope index
|
||||||
, scopeDepth
|
, scopeDepth
|
||||||
// A list of all global identifier nodes.
|
// A list of all global identifier nodes.
|
||||||
, globals
|
, globals;
|
||||||
// A list of all global identifiers names used for faster lookup.
|
|
||||||
// @TODO benchmark, with exposing the globals this entire implementation
|
|
||||||
// should probably change.
|
|
||||||
, globalNames;
|
|
||||||
|
|
||||||
// Create a new scope inheriting all declarations from the previous scope.
|
// Create a new scope inheriting all declarations from the previous scope.
|
||||||
function createScope() {
|
function createScope() {
|
||||||
|
|
@ -1080,10 +1104,8 @@ define(function(require, exports, module) {
|
||||||
// Attach scope information to node. If the node is global, store it in the
|
// Attach scope information to node. If the node is global, store it in the
|
||||||
// globals array so we can return the information to the user.
|
// globals array so we can return the information to the user.
|
||||||
function attachScope(node, isLocal) {
|
function attachScope(node, isLocal) {
|
||||||
if (!isLocal && -1 === indexOf(globalNames, node.name)) {
|
if (!isLocal && -1 === indexOfObject(globals, 'name', node.name))
|
||||||
globalNames.push(node.name);
|
|
||||||
globals.push(node);
|
globals.push(node);
|
||||||
}
|
|
||||||
|
|
||||||
node.isLocal = isLocal;
|
node.isLocal = isLocal;
|
||||||
}
|
}
|
||||||
|
|
@ -1093,6 +1115,57 @@ define(function(require, exports, module) {
|
||||||
return (-1 !== indexOf(scopes[scopeDepth], name));
|
return (-1 !== indexOf(scopes[scopeDepth], name));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Location tracking
|
||||||
|
// -----------------
|
||||||
|
//
|
||||||
|
// Locations are stored in FILO-array as a `Marker` object consisting of both
|
||||||
|
// `loc` and `range` data. Once a `Marker` is popped off the list an end
|
||||||
|
// location is added and the data is attached to a syntax node.
|
||||||
|
|
||||||
|
var locations = []
|
||||||
|
, trackLocations;
|
||||||
|
|
||||||
|
function createLocationMarker() {
|
||||||
|
return new Marker(token);
|
||||||
|
}
|
||||||
|
|
||||||
|
function Marker(token) {
|
||||||
|
if (options.locations) {
|
||||||
|
this.loc = {
|
||||||
|
start: {
|
||||||
|
line: token.line
|
||||||
|
, column: token.range[0] - token.lineStart
|
||||||
|
}
|
||||||
|
, end: {
|
||||||
|
line: 0
|
||||||
|
, column: 0
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if (options.ranges) this.range = [token.range[0], 0];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Complete the location data stored in the `Marker` by adding the location
|
||||||
|
// of the *previous token* as an end location.
|
||||||
|
Marker.prototype.complete = function() {
|
||||||
|
if (options.locations) {
|
||||||
|
this.loc.end.line = previousToken.line;
|
||||||
|
this.loc.end.column = previousToken.range[1] - previousToken.lineStart;
|
||||||
|
}
|
||||||
|
if (options.ranges) {
|
||||||
|
this.range[1] = previousToken.range[1];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Create a new `Marker` and add it to the FILO-array.
|
||||||
|
function markLocation() {
|
||||||
|
if (trackLocations) locations.push(createLocationMarker());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Push an arbitrary `Marker` object onto the FILO-array.
|
||||||
|
function pushLocation(marker) {
|
||||||
|
if (trackLocations) locations.push(marker);
|
||||||
|
}
|
||||||
|
|
||||||
// Parse functions
|
// Parse functions
|
||||||
// ---------------
|
// ---------------
|
||||||
|
|
@ -1103,9 +1176,12 @@ define(function(require, exports, module) {
|
||||||
|
|
||||||
function parseChunk() {
|
function parseChunk() {
|
||||||
next();
|
next();
|
||||||
|
markLocation();
|
||||||
var body = parseBlock();
|
var body = parseBlock();
|
||||||
if (EOF !== token.type) unexpected(token);
|
if (EOF !== token.type) unexpected(token);
|
||||||
return ast.chunk(body);
|
// If the body is empty no previousToken exists when finishNode runs.
|
||||||
|
if (trackLocations && !body.length) previousToken = token;
|
||||||
|
return finishNode(ast.chunk(body));
|
||||||
}
|
}
|
||||||
|
|
||||||
// A block contains a list of statements with an optional return statement
|
// A block contains a list of statements with an optional return statement
|
||||||
|
|
@ -1144,6 +1220,7 @@ define(function(require, exports, module) {
|
||||||
// | functioncall | ';'
|
// | functioncall | ';'
|
||||||
|
|
||||||
function parseStatement() {
|
function parseStatement() {
|
||||||
|
markLocation();
|
||||||
if (Keyword === token.type) {
|
if (Keyword === token.type) {
|
||||||
switch (token.value) {
|
switch (token.value) {
|
||||||
case 'local': next(); return parseLocalStatement();
|
case 'local': next(); return parseLocalStatement();
|
||||||
|
|
@ -1164,6 +1241,9 @@ define(function(require, exports, module) {
|
||||||
if (Punctuator === token.type) {
|
if (Punctuator === token.type) {
|
||||||
if (consume('::')) return parseLabelStatement();
|
if (consume('::')) return parseLabelStatement();
|
||||||
}
|
}
|
||||||
|
// Assignments memorizes the location and pushes it manually for wrapper
|
||||||
|
// nodes. Additionally empty `;` statements should not mark a location.
|
||||||
|
if (trackLocations) locations.pop();
|
||||||
|
|
||||||
// When a `;` is encounted, simply eat it without storing it.
|
// When a `;` is encounted, simply eat it without storing it.
|
||||||
if (consume(';')) return;
|
if (consume(';')) return;
|
||||||
|
|
@ -1185,13 +1265,13 @@ define(function(require, exports, module) {
|
||||||
}
|
}
|
||||||
|
|
||||||
expect('::');
|
expect('::');
|
||||||
return ast.labelStatement(label);
|
return finishNode(ast.labelStatement(label));
|
||||||
}
|
}
|
||||||
|
|
||||||
// break ::= 'break'
|
// break ::= 'break'
|
||||||
|
|
||||||
function parseBreakStatement() {
|
function parseBreakStatement() {
|
||||||
return ast.breakStatement();
|
return finishNode(ast.breakStatement());
|
||||||
}
|
}
|
||||||
|
|
||||||
// goto ::= 'goto' Name
|
// goto ::= 'goto' Name
|
||||||
|
|
@ -1201,7 +1281,7 @@ define(function(require, exports, module) {
|
||||||
, label = parseIdentifier();
|
, label = parseIdentifier();
|
||||||
|
|
||||||
if (options.scope) label.isLabel = scopeHasName('::' + name + '::');
|
if (options.scope) label.isLabel = scopeHasName('::' + name + '::');
|
||||||
return ast.gotoStatement(label);
|
return finishNode(ast.gotoStatement(label));
|
||||||
}
|
}
|
||||||
|
|
||||||
// do ::= 'do' block 'end'
|
// do ::= 'do' block 'end'
|
||||||
|
|
@ -1209,7 +1289,7 @@ define(function(require, exports, module) {
|
||||||
function parseDoStatement() {
|
function parseDoStatement() {
|
||||||
var body = parseBlock();
|
var body = parseBlock();
|
||||||
expect('end');
|
expect('end');
|
||||||
return ast.doStatement(body);
|
return finishNode(ast.doStatement(body));
|
||||||
}
|
}
|
||||||
|
|
||||||
// while ::= 'while' exp 'do' block 'end'
|
// while ::= 'while' exp 'do' block 'end'
|
||||||
|
|
@ -1219,7 +1299,7 @@ define(function(require, exports, module) {
|
||||||
expect('do');
|
expect('do');
|
||||||
var body = parseBlock();
|
var body = parseBlock();
|
||||||
expect('end');
|
expect('end');
|
||||||
return ast.whileStatement(condition, body);
|
return finishNode(ast.whileStatement(condition, body));
|
||||||
}
|
}
|
||||||
|
|
||||||
// repeat ::= 'repeat' block 'until' exp
|
// repeat ::= 'repeat' block 'until' exp
|
||||||
|
|
@ -1228,7 +1308,7 @@ define(function(require, exports, module) {
|
||||||
var body = parseBlock();
|
var body = parseBlock();
|
||||||
expect('until');
|
expect('until');
|
||||||
var condition = parseExpectedExpression();
|
var condition = parseExpectedExpression();
|
||||||
return ast.repeatStatement(condition, body);
|
return finishNode(ast.repeatStatement(condition, body));
|
||||||
}
|
}
|
||||||
|
|
||||||
// retstat ::= 'return' [exp {',' exp}] [';']
|
// retstat ::= 'return' [exp {',' exp}] [';']
|
||||||
|
|
@ -1245,7 +1325,7 @@ define(function(require, exports, module) {
|
||||||
}
|
}
|
||||||
consume(';'); // grammar tells us ; is optional here.
|
consume(';'); // grammar tells us ; is optional here.
|
||||||
}
|
}
|
||||||
return ast.returnStatement(expressions);
|
return finishNode(ast.returnStatement(expressions));
|
||||||
}
|
}
|
||||||
|
|
||||||
// if ::= 'if' exp 'then' block {elif} ['else' block] 'end'
|
// if ::= 'if' exp 'then' block {elif} ['else' block] 'end'
|
||||||
|
|
@ -1254,27 +1334,42 @@ define(function(require, exports, module) {
|
||||||
function parseIfStatement() {
|
function parseIfStatement() {
|
||||||
var clauses = []
|
var clauses = []
|
||||||
, condition
|
, condition
|
||||||
, body;
|
, body
|
||||||
|
, marker;
|
||||||
|
|
||||||
|
// IfClauses begin at the same location as the parent IfStatement.
|
||||||
|
// It ends at the start of `end`, `else`, or `elseif`.
|
||||||
|
if (trackLocations) {
|
||||||
|
marker = locations[locations.length - 1];
|
||||||
|
locations.push(marker);
|
||||||
|
}
|
||||||
condition = parseExpectedExpression();
|
condition = parseExpectedExpression();
|
||||||
expect('then');
|
expect('then');
|
||||||
body = parseBlock();
|
body = parseBlock();
|
||||||
clauses.push(ast.ifClause(condition, body));
|
clauses.push(finishNode(ast.ifClause(condition, body)));
|
||||||
|
|
||||||
|
if (trackLocations) marker = createLocationMarker();
|
||||||
while (consume('elseif')) {
|
while (consume('elseif')) {
|
||||||
|
pushLocation(marker);
|
||||||
condition = parseExpectedExpression();
|
condition = parseExpectedExpression();
|
||||||
expect('then');
|
expect('then');
|
||||||
body = parseBlock();
|
body = parseBlock();
|
||||||
clauses.push(ast.elseifClause(condition, body));
|
clauses.push(finishNode(ast.elseifClause(condition, body)));
|
||||||
|
if (trackLocations) marker = createLocationMarker();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (consume('else')) {
|
if (consume('else')) {
|
||||||
|
// Include the `else` in the location of ElseClause.
|
||||||
|
if (trackLocations) {
|
||||||
|
marker = new Marker(previousToken);
|
||||||
|
locations.push(marker);
|
||||||
|
}
|
||||||
body = parseBlock();
|
body = parseBlock();
|
||||||
clauses.push(ast.elseClause(body));
|
clauses.push(finishNode(ast.elseClause(body)));
|
||||||
}
|
}
|
||||||
|
|
||||||
expect('end');
|
expect('end');
|
||||||
return ast.ifStatement(clauses);
|
return finishNode(ast.ifStatement(clauses));
|
||||||
}
|
}
|
||||||
|
|
||||||
// There are two types of for statements, generic and numeric.
|
// There are two types of for statements, generic and numeric.
|
||||||
|
|
@ -1306,7 +1401,7 @@ define(function(require, exports, module) {
|
||||||
body = parseBlock();
|
body = parseBlock();
|
||||||
expect('end');
|
expect('end');
|
||||||
|
|
||||||
return ast.forNumericStatement(variable, start, end, step, body);
|
return finishNode(ast.forNumericStatement(variable, start, end, step, body));
|
||||||
}
|
}
|
||||||
// If not, it's a Generic For Statement
|
// If not, it's a Generic For Statement
|
||||||
else {
|
else {
|
||||||
|
|
@ -1331,7 +1426,7 @@ define(function(require, exports, module) {
|
||||||
body = parseBlock();
|
body = parseBlock();
|
||||||
expect('end');
|
expect('end');
|
||||||
|
|
||||||
return ast.forGenericStatement(variables, iterators, body);
|
return finishNode(ast.forGenericStatement(variables, iterators, body));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1374,7 +1469,7 @@ define(function(require, exports, module) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ast.localStatement(variables, init);
|
return finishNode(ast.localStatement(variables, init));
|
||||||
}
|
}
|
||||||
if (consume('function')) {
|
if (consume('function')) {
|
||||||
name = parseIdentifier();
|
name = parseIdentifier();
|
||||||
|
|
@ -1398,7 +1493,10 @@ define(function(require, exports, module) {
|
||||||
// Keep a reference to the previous token for better error messages in case
|
// Keep a reference to the previous token for better error messages in case
|
||||||
// of invalid statement
|
// of invalid statement
|
||||||
var previous = token
|
var previous = token
|
||||||
, expression = parsePrefixExpression();
|
, expression, marker;
|
||||||
|
|
||||||
|
if (trackLocations) marker = createLocationMarker();
|
||||||
|
expression = parsePrefixExpression();
|
||||||
|
|
||||||
if (null == expression) return unexpected(token);
|
if (null == expression) return unexpected(token);
|
||||||
if (',='.indexOf(token.value) >= 0) {
|
if (',='.indexOf(token.value) >= 0) {
|
||||||
|
|
@ -1416,10 +1514,13 @@ define(function(require, exports, module) {
|
||||||
exp = parseExpectedExpression();
|
exp = parseExpectedExpression();
|
||||||
init.push(exp);
|
init.push(exp);
|
||||||
} while (consume(','));
|
} while (consume(','));
|
||||||
return ast.assignmentStatement(variables, init);
|
|
||||||
|
pushLocation(marker);
|
||||||
|
return finishNode(ast.assignmentStatement(variables, init));
|
||||||
}
|
}
|
||||||
if (isCallExpression(expression)) {
|
if (isCallExpression(expression)) {
|
||||||
return ast.callStatement(expression);
|
pushLocation(marker);
|
||||||
|
return finishNode(ast.callStatement(expression));
|
||||||
}
|
}
|
||||||
// The prefix expression was neither part of an assignment or a
|
// The prefix expression was neither part of an assignment or a
|
||||||
// callstatement, however as it was valid it's been consumed, so raise
|
// callstatement, however as it was valid it's been consumed, so raise
|
||||||
|
|
@ -1434,10 +1535,11 @@ define(function(require, exports, module) {
|
||||||
// Identifier ::= Name
|
// Identifier ::= Name
|
||||||
|
|
||||||
function parseIdentifier() {
|
function parseIdentifier() {
|
||||||
|
markLocation();
|
||||||
var identifier = token.value;
|
var identifier = token.value;
|
||||||
if (Identifier !== token.type) raiseUnexpectedToken('<name>', token);
|
if (Identifier !== token.type) raiseUnexpectedToken('<name>', token);
|
||||||
next();
|
next();
|
||||||
return ast.identifier(identifier);
|
return finishNode(ast.identifier(identifier));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse the functions parameters and body block. The name should already
|
// Parse the functions parameters and body block. The name should already
|
||||||
|
|
@ -1484,7 +1586,7 @@ define(function(require, exports, module) {
|
||||||
expect('end');
|
expect('end');
|
||||||
|
|
||||||
isLocal = isLocal || false;
|
isLocal = isLocal || false;
|
||||||
return ast.functionStatement(name, parameters, isLocal, body);
|
return finishNode(ast.functionStatement(name, parameters, isLocal, body));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse the function name as identifiers and member expressions.
|
// Parse the function name as identifiers and member expressions.
|
||||||
|
|
@ -1492,20 +1594,25 @@ define(function(require, exports, module) {
|
||||||
// Name {'.' Name} [':' Name]
|
// Name {'.' Name} [':' Name]
|
||||||
|
|
||||||
function parseFunctionName() {
|
function parseFunctionName() {
|
||||||
var base = parseIdentifier()
|
var base, name, marker;
|
||||||
, name;
|
|
||||||
|
if (trackLocations) marker = createLocationMarker();
|
||||||
|
base = parseIdentifier();
|
||||||
|
|
||||||
if (options.scope) attachScope(base, false);
|
if (options.scope) attachScope(base, false);
|
||||||
|
|
||||||
while (consume('.')) {
|
while (consume('.')) {
|
||||||
|
pushLocation(marker);
|
||||||
name = parseIdentifier();
|
name = parseIdentifier();
|
||||||
if (options.scope) attachScope(name, false);
|
if (options.scope) attachScope(name, false);
|
||||||
base = ast.memberExpression(base, '.', name);
|
base = finishNode(ast.memberExpression(base, '.', name));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (consume(':')) {
|
if (consume(':')) {
|
||||||
|
pushLocation(marker);
|
||||||
name = parseIdentifier();
|
name = parseIdentifier();
|
||||||
if (options.scope) attachScope(name, false);
|
if (options.scope) attachScope(name, false);
|
||||||
base = ast.memberExpression(base, ':', name);
|
base = finishNode(ast.memberExpression(base, ':', name));
|
||||||
}
|
}
|
||||||
|
|
||||||
return base;
|
return base;
|
||||||
|
|
@ -1522,23 +1629,27 @@ define(function(require, exports, module) {
|
||||||
, key, value;
|
, key, value;
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
|
markLocation();
|
||||||
if (Punctuator === token.type && consume('[')) {
|
if (Punctuator === token.type && consume('[')) {
|
||||||
key = parseExpectedExpression();
|
key = parseExpectedExpression();
|
||||||
expect(']');
|
expect(']');
|
||||||
expect('=');
|
expect('=');
|
||||||
value = parseExpectedExpression();
|
value = parseExpectedExpression();
|
||||||
fields.push(ast.tableKey(key, value));
|
fields.push(finishNode(ast.tableKey(key, value)));
|
||||||
} else if (Identifier === token.type) {
|
} else if (Identifier === token.type) {
|
||||||
key = parseExpectedExpression();
|
key = parseExpectedExpression();
|
||||||
if (consume('=')) {
|
if (consume('=')) {
|
||||||
value = parseExpectedExpression();
|
value = parseExpectedExpression();
|
||||||
fields.push(ast.tableKeyString(key, value));
|
fields.push(finishNode(ast.tableKeyString(key, value)));
|
||||||
} else {
|
} else {
|
||||||
fields.push(ast.tableValue(key));
|
fields.push(finishNode(ast.tableValue(key)));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (null == (value = parseExpression())) break;
|
if (null == (value = parseExpression())) {
|
||||||
fields.push(ast.tableValue(value));
|
locations.pop();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
fields.push(finishNode(ast.tableValue(value)));
|
||||||
}
|
}
|
||||||
if (',;'.indexOf(token.value) >= 0) {
|
if (',;'.indexOf(token.value) >= 0) {
|
||||||
next();
|
next();
|
||||||
|
|
@ -1547,7 +1658,7 @@ define(function(require, exports, module) {
|
||||||
if ('}' === token.value) break;
|
if ('}' === token.value) break;
|
||||||
}
|
}
|
||||||
expect('}');
|
expect('}');
|
||||||
return ast.tableConstructorExpression(fields);
|
return finishNode(ast.tableConstructorExpression(fields));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Expression parser
|
// Expression parser
|
||||||
|
|
@ -1588,23 +1699,23 @@ define(function(require, exports, module) {
|
||||||
// the expensive CompareICStub which took ~8% of the parse time.
|
// the expensive CompareICStub which took ~8% of the parse time.
|
||||||
|
|
||||||
function binaryPrecedence(operator) {
|
function binaryPrecedence(operator) {
|
||||||
var character = operator.charCodeAt(0)
|
var charCode = operator.charCodeAt(0)
|
||||||
, length = operator.length;
|
, length = operator.length;
|
||||||
|
|
||||||
if (1 === length) {
|
if (1 === length) {
|
||||||
switch (character) {
|
switch (charCode) {
|
||||||
case 94: return 10; // ^
|
case 94: return 10; // ^
|
||||||
case 42: case 47: case 37: return 7; // * / %
|
case 42: case 47: case 37: return 7; // * / %
|
||||||
case 43: case 45: return 6; // + -
|
case 43: case 45: return 6; // + -
|
||||||
case 60: case 62: return 3; // < >
|
case 60: case 62: return 3; // < >
|
||||||
}
|
}
|
||||||
} else if (2 === length) {
|
} else if (2 === length) {
|
||||||
switch (character) {
|
switch (charCode) {
|
||||||
case 46: return 5; // ..
|
case 46: return 5; // ..
|
||||||
case 60: case 62: case 61: case 126: return 3; // <= >= == ~=
|
case 60: case 62: case 61: case 126: return 3; // <= >= == ~=
|
||||||
case 111: return 1; // or
|
case 111: return 1; // or
|
||||||
}
|
}
|
||||||
} else if (97 === character && 'and' === operator) return 2;
|
} else if (97 === charCode && 'and' === operator) return 2;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1618,16 +1729,19 @@ define(function(require, exports, module) {
|
||||||
// exp ::= (unop exp | primary | prefixexp ) { binop exp }
|
// exp ::= (unop exp | primary | prefixexp ) { binop exp }
|
||||||
|
|
||||||
function parseSubExpression(minPrecedence) {
|
function parseSubExpression(minPrecedence) {
|
||||||
var operator = token.value;
|
var operator = token.value
|
||||||
// The left-hand side in binary operations.
|
// The left-hand side in binary operations.
|
||||||
var expression;
|
, expression, marker;
|
||||||
|
|
||||||
|
if (trackLocations) marker = createLocationMarker();
|
||||||
|
|
||||||
// UnaryExpression
|
// UnaryExpression
|
||||||
if (isUnary(token)) {
|
if (isUnary(token)) {
|
||||||
|
markLocation();
|
||||||
next();
|
next();
|
||||||
var argument = parseSubExpression(8);
|
var argument = parseSubExpression(8);
|
||||||
if (argument == null) raiseUnexpectedToken('<expression>', token);
|
if (argument == null) raiseUnexpectedToken('<expression>', token);
|
||||||
expression = ast.unaryExpression(operator, argument);
|
expression = finishNode(ast.unaryExpression(operator, argument));
|
||||||
}
|
}
|
||||||
if (null == expression) {
|
if (null == expression) {
|
||||||
// PrimaryExpression
|
// PrimaryExpression
|
||||||
|
|
@ -1654,7 +1768,10 @@ define(function(require, exports, module) {
|
||||||
next();
|
next();
|
||||||
var right = parseSubExpression(precedence);
|
var right = parseSubExpression(precedence);
|
||||||
if (null == right) raiseUnexpectedToken('<expression>', token);
|
if (null == right) raiseUnexpectedToken('<expression>', token);
|
||||||
expression = ast.binaryExpression(operator, expression, right);
|
// Push in the marker created before the loop to wrap its entirety.
|
||||||
|
if (trackLocations) locations.push(marker);
|
||||||
|
expression = finishNode(ast.binaryExpression(operator, expression, right));
|
||||||
|
|
||||||
}
|
}
|
||||||
return expression;
|
return expression;
|
||||||
}
|
}
|
||||||
|
|
@ -1666,10 +1783,12 @@ define(function(require, exports, module) {
|
||||||
// args ::= '(' [explist] ')' | tableconstructor | String
|
// args ::= '(' [explist] ')' | tableconstructor | String
|
||||||
|
|
||||||
function parsePrefixExpression() {
|
function parsePrefixExpression() {
|
||||||
var base, name
|
var base, name, marker
|
||||||
// Keep track of the scope, if a parent is local so are the children.
|
// Keep track of the scope, if a parent is local so are the children.
|
||||||
, isLocal;
|
, isLocal;
|
||||||
|
|
||||||
|
if (trackLocations) marker = createLocationMarker();
|
||||||
|
|
||||||
// The prefix
|
// The prefix
|
||||||
if (Identifier === token.type) {
|
if (Identifier === token.type) {
|
||||||
name = token.value;
|
name = token.value;
|
||||||
|
|
@ -1690,34 +1809,40 @@ define(function(require, exports, module) {
|
||||||
if (Punctuator === token.type) {
|
if (Punctuator === token.type) {
|
||||||
switch (token.value) {
|
switch (token.value) {
|
||||||
case '[':
|
case '[':
|
||||||
|
pushLocation(marker);
|
||||||
next();
|
next();
|
||||||
expression = parseExpectedExpression();
|
expression = parseExpectedExpression();
|
||||||
base = ast.indexExpression(base, expression);
|
base = finishNode(ast.indexExpression(base, expression));
|
||||||
expect(']');
|
expect(']');
|
||||||
break;
|
break;
|
||||||
case '.':
|
case '.':
|
||||||
|
pushLocation(marker);
|
||||||
next();
|
next();
|
||||||
identifier = parseIdentifier();
|
identifier = parseIdentifier();
|
||||||
// Inherit the scope
|
// Inherit the scope
|
||||||
if (options.scope) attachScope(identifier, isLocal);
|
if (options.scope) attachScope(identifier, isLocal);
|
||||||
base = ast.memberExpression(base, '.', identifier);
|
base = finishNode(ast.memberExpression(base, '.', identifier));
|
||||||
break;
|
break;
|
||||||
case ':':
|
case ':':
|
||||||
|
pushLocation(marker);
|
||||||
next();
|
next();
|
||||||
identifier = parseIdentifier();
|
identifier = parseIdentifier();
|
||||||
if (options.scope) attachScope(identifier, isLocal);
|
if (options.scope) attachScope(identifier, isLocal);
|
||||||
base = ast.memberExpression(base, ':', identifier);
|
base = finishNode(ast.memberExpression(base, ':', identifier));
|
||||||
// Once a : is found, this has to be a callexpression, otherwise
|
// Once a : is found, this has to be a CallExpression, otherwise
|
||||||
// throw an error.
|
// throw an error.
|
||||||
|
pushLocation(marker);
|
||||||
base = parseCallExpression(base);
|
base = parseCallExpression(base);
|
||||||
break;
|
break;
|
||||||
case '(': case '{': // args
|
case '(': case '{': // args
|
||||||
|
pushLocation(marker);
|
||||||
base = parseCallExpression(base);
|
base = parseCallExpression(base);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return base;
|
return base;
|
||||||
}
|
}
|
||||||
} else if (StringLiteral === token.type) {
|
} else if (StringLiteral === token.type) {
|
||||||
|
pushLocation(marker);
|
||||||
base = parseCallExpression(base);
|
base = parseCallExpression(base);
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
|
|
@ -1745,15 +1870,16 @@ define(function(require, exports, module) {
|
||||||
}
|
}
|
||||||
|
|
||||||
expect(')');
|
expect(')');
|
||||||
return ast.callExpression(base, expressions);
|
return finishNode(ast.callExpression(base, expressions));
|
||||||
|
|
||||||
case '{':
|
case '{':
|
||||||
|
markLocation();
|
||||||
next();
|
next();
|
||||||
var table = parseTableConstructor();
|
var table = parseTableConstructor();
|
||||||
return ast.tableCallExpression(base, table);
|
return finishNode(ast.tableCallExpression(base, table));
|
||||||
}
|
}
|
||||||
} else if (StringLiteral === token.type) {
|
} else if (StringLiteral === token.type) {
|
||||||
return ast.stringCallExpression(base, parsePrimaryExpression());
|
return finishNode(ast.stringCallExpression(base, parsePrimaryExpression()));
|
||||||
}
|
}
|
||||||
|
|
||||||
raiseUnexpectedToken('function arguments', token);
|
raiseUnexpectedToken('function arguments', token);
|
||||||
|
|
@ -1765,17 +1891,24 @@ define(function(require, exports, module) {
|
||||||
function parsePrimaryExpression() {
|
function parsePrimaryExpression() {
|
||||||
var literals = StringLiteral | NumericLiteral | BooleanLiteral | NilLiteral | VarargLiteral
|
var literals = StringLiteral | NumericLiteral | BooleanLiteral | NilLiteral | VarargLiteral
|
||||||
, value = token.value
|
, value = token.value
|
||||||
, type = token.type;
|
, type = token.type
|
||||||
|
, marker;
|
||||||
|
|
||||||
|
if (trackLocations) marker = createLocationMarker();
|
||||||
|
|
||||||
if (type & literals) {
|
if (type & literals) {
|
||||||
|
pushLocation(marker);
|
||||||
var raw = input.slice(token.range[0], token.range[1]);
|
var raw = input.slice(token.range[0], token.range[1]);
|
||||||
next();
|
next();
|
||||||
return ast.literal(type, value, raw);
|
return finishNode(ast.literal(type, value, raw));
|
||||||
} else if (Keyword === type && 'function' === value) {
|
} else if (Keyword === type && 'function' === value) {
|
||||||
|
pushLocation(marker);
|
||||||
next();
|
next();
|
||||||
return parseFunctionDeclaration(null);
|
return parseFunctionDeclaration(null);
|
||||||
} else if (consume('{'))
|
} else if (consume('{')) {
|
||||||
|
pushLocation(marker);
|
||||||
return parseTableConstructor();
|
return parseTableConstructor();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parser
|
// Parser
|
||||||
|
|
@ -1813,7 +1946,7 @@ define(function(require, exports, module) {
|
||||||
scopes = [[]];
|
scopes = [[]];
|
||||||
scopeDepth = 0;
|
scopeDepth = 0;
|
||||||
globals = [];
|
globals = [];
|
||||||
globalNames = [];
|
locations = [];
|
||||||
|
|
||||||
if (options.comments) comments = [];
|
if (options.comments) comments = [];
|
||||||
if (!options.wait) return end();
|
if (!options.wait) return end();
|
||||||
|
|
@ -1836,12 +1969,17 @@ define(function(require, exports, module) {
|
||||||
if ('undefined' !== typeof _input) write(_input);
|
if ('undefined' !== typeof _input) write(_input);
|
||||||
|
|
||||||
length = input.length;
|
length = input.length;
|
||||||
|
trackLocations = options.locations || options.ranges;
|
||||||
// Initialize with a lookahead token.
|
// Initialize with a lookahead token.
|
||||||
lookahead = lex();
|
lookahead = lex();
|
||||||
|
|
||||||
var chunk = parseChunk();
|
var chunk = parseChunk();
|
||||||
if (options.comments) chunk.comments = comments;
|
if (options.comments) chunk.comments = comments;
|
||||||
if (options.scope) chunk.globals = globals;
|
if (options.scope) chunk.globals = globals;
|
||||||
|
|
||||||
|
if (locations.length > 0)
|
||||||
|
throw new Error('Location tracking failed. This is most likely a bug in luaparse');
|
||||||
|
|
||||||
return chunk;
|
return chunk;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,8 @@ window.console = {
|
||||||
error: function() {
|
error: function() {
|
||||||
var msgs = Array.prototype.slice.call(arguments, 0);
|
var msgs = Array.prototype.slice.call(arguments, 0);
|
||||||
postMessage({type: "log", data: msgs});
|
postMessage({type: "log", data: msgs});
|
||||||
}
|
},
|
||||||
|
trace: function() {}
|
||||||
};
|
};
|
||||||
window.window = window;
|
window.window = window;
|
||||||
window.ace = window;
|
window.ace = window;
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,13 @@ var deps = [{
|
||||||
}, {
|
}, {
|
||||||
path: "mode/lua/luaparse.js",
|
path: "mode/lua/luaparse.js",
|
||||||
url: "https://raw.github.com/oxyc/luaparse/master/luaparse.js",
|
url: "https://raw.github.com/oxyc/luaparse/master/luaparse.js",
|
||||||
needsFixup: true
|
needsFixup: true,
|
||||||
|
postProcess: function(src) {
|
||||||
|
return src.replace(
|
||||||
|
/\(function\s*\(root,\s*name,\s*factory\)\s*{[\s\S]*?}\(this,\s*'luaparse',/,
|
||||||
|
"(function (root, name, factory) {\n factory(exports)\n}(this, 'luaparse',"
|
||||||
|
)
|
||||||
|
}
|
||||||
}];
|
}];
|
||||||
|
|
||||||
var download = function(href, callback) {
|
var download = function(href, callback) {
|
||||||
|
|
@ -39,12 +45,12 @@ var download = function(href, callback) {
|
||||||
|
|
||||||
var getDep = function(dep) {
|
var getDep = function(dep) {
|
||||||
download(dep.url, function(data) {
|
download(dep.url, function(data) {
|
||||||
|
if (dep.postProcess)
|
||||||
|
data = dep.postProcess(data);
|
||||||
if (dep.needsFixup)
|
if (dep.needsFixup)
|
||||||
data = "define(function(require, exports, module) {\n"
|
data = "define(function(require, exports, module) {\n"
|
||||||
+ data
|
+ data
|
||||||
+ "\n});";
|
+ "\n});";
|
||||||
if (dep.postProcess)
|
|
||||||
data = dep.postProcess(data);
|
|
||||||
|
|
||||||
fs.writeFile(rootDir + dep.path, data, "utf-8", function(err){
|
fs.writeFile(rootDir + dep.path, data, "utf-8", function(err){
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
|
|
@ -173,10 +179,19 @@ run("npm install jshint", function() {
|
||||||
/"Expected a conditional expression and instead saw an assignment."/g,
|
/"Expected a conditional expression and instead saw an assignment."/g,
|
||||||
'"Assignment in conditional expression"'
|
'"Assignment in conditional expression"'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
jshintDist = jshintDist.replace(/\brequire\(["']|\(require,|\(require\)/g, function(r){
|
||||||
|
return r.replace("require", "req");
|
||||||
|
}).replace(/\brequire.define\(/g, function(d){
|
||||||
|
return d.replace("define", "def");
|
||||||
|
});
|
||||||
|
|
||||||
|
jshintDist = jshintDist.replace(/var defaultMaxListeners = 10;/, function(a) {return a.replace("10", "200")});
|
||||||
|
|
||||||
jshintDist = 'define(function() {\n'
|
jshintDist = 'define(function() {\n'
|
||||||
+ jshintDist + '\n'
|
+ jshintDist + '\n'
|
||||||
+ 'var jsHint = require("/src/stable/jshint.js");\n'
|
+ 'function req() {return require.apply(this, arguments)}'
|
||||||
+ 'return function(require, exports, module) {module.exports = jsHint;}\n'
|
+ 'module.exports = req("/src/stable/jshint.js");\n'
|
||||||
+'}())';
|
+'})';
|
||||||
fs.writeFileSync(rootDir + "mode/javascript/jshint.js", jshintDist);
|
fs.writeFileSync(rootDir + "mode/javascript/jshint.js", jshintDist);
|
||||||
});
|
});
|
||||||
Loading…
Add table
Add a link
Reference in a new issue