From b079a056a2c2f283e95ae3f371253fe09a1f5048 Mon Sep 17 00:00:00 2001 From: Arlo Breault Date: Fri, 5 Jun 2015 15:05:21 -0700 Subject: [PATCH 1/3] Suppress linting newcap * When the "use strict"; directive is set, constructors called without `new` will set the execution context to undefined. JSHint tries to be clever and forces on newcap. Suppress this behaviour, especially because newcap has gone the way of the dodo. --- .jshintrc | 1 + 1 file changed, 1 insertion(+) diff --git a/.jshintrc b/.jshintrc index d9bd925..218394a 100644 --- a/.jshintrc +++ b/.jshintrc @@ -8,6 +8,7 @@ "latedef": "nofunc", "laxbreak": true, "loopfunc": true, + "newcap": false, "noarg": true, "noempty": true, "nonew": true, From 7285ccfd4eac501a349cadf31f1c9ab68d99bbf6 Mon Sep 17 00:00:00 2001 From: Arlo Breault Date: Fri, 5 Jun 2015 15:33:35 -0700 Subject: [PATCH 2/3] Remove block around initialize code * In strict mode code, functions can only be declared at top level or immediately within another function. This means functions defined in the initializer would throw. --- lib/compiler/passes/generate-javascript.js | 2 +- lib/parser.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/compiler/passes/generate-javascript.js b/lib/compiler/passes/generate-javascript.js index eddf6fd..c38d4b8 100644 --- a/lib/compiler/passes/generate-javascript.js +++ b/lib/compiler/passes/generate-javascript.js @@ -1147,7 +1147,7 @@ function generateJavascript(ast, options) { } if (ast.initializer) { - parts.push(indent4("{" + ast.initializer.code + "}")); + parts.push(indent4(ast.initializer.code)); parts.push(''); } diff --git a/lib/parser.js b/lib/parser.js index 48078e6..d402a52 100644 --- a/lib/parser.js +++ b/lib/parser.js @@ -4893,7 +4893,7 @@ module.exports = (function() { return s0; } - { + var OPS_TO_PREFIXED_TYPES = { "$": "text", "&": "simple_and", @@ -4940,7 +4940,7 @@ module.exports = (function() { function buildList(first, rest, index) { return [first].concat(extractList(rest, index)); } - } + peg$result = peg$startRuleFunction(); From 45e39c3ac881cbd98077e97a3d8788c817a2de53 Mon Sep 17 00:00:00 2001 From: Arlo Breault Date: Fri, 5 Jun 2015 16:11:41 -0700 Subject: [PATCH 3/3] Make generated parsers use strict mode * Issue #324 * JSHint complains about two possible strict violations. But are valid uses of `this`, so we suppress the warnings. --- .jshintrc | 31 +++++++++++----------- lib/compiler/passes/generate-javascript.js | 2 ++ lib/parser.js | 2 ++ 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/.jshintrc b/.jshintrc index 218394a..0fdd54e 100644 --- a/.jshintrc +++ b/.jshintrc @@ -1,17 +1,18 @@ { - "curly": true, - "eqeqeq": true, - "evil": true, - "forin": true, - "freeze": true, - "immed": true, - "latedef": "nofunc", - "laxbreak": true, - "loopfunc": true, - "newcap": false, - "noarg": true, - "noempty": true, - "nonew": true, - "trailing": true, - "-W082": false + "curly": true, + "eqeqeq": true, + "evil": true, + "forin": true, + "freeze": true, + "immed": true, + "latedef": "nofunc", + "laxbreak": true, + "loopfunc": true, + "newcap": false, + "noarg": true, + "noempty": true, + "nonew": true, + "trailing": true, + "validthis": true, + "-W082": false } diff --git a/lib/compiler/passes/generate-javascript.js b/lib/compiler/passes/generate-javascript.js index c38d4b8..1268774 100644 --- a/lib/compiler/passes/generate-javascript.js +++ b/lib/compiler/passes/generate-javascript.js @@ -761,6 +761,8 @@ function generateJavascript(ast, options) { parts.push([ '(function() {', + ' "use strict";', + '', ' /*', ' * Generated by PEG.js 0.8.0.', ' *', diff --git a/lib/parser.js b/lib/parser.js index d402a52..b6b677f 100644 --- a/lib/parser.js +++ b/lib/parser.js @@ -1,4 +1,6 @@ module.exports = (function() { + "use strict"; + /* * Generated by PEG.js 0.8.0. *