Skip to content

Commit 62bdeb7

Browse files
committed
Fix missing acorn_loose for our JS parser
1 parent fb00fe1 commit 62bdeb7

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

app/lib/aether/languages/javascript.coffee

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
_ = window?._ ? self?._ ? global?._ ? require 'lodash' # rely on lodash existing, since it busts CodeCombat to browserify it--TODO
22

33
jshintHolder = {}
4+
acorn_loose = require 'acorn-loose'
45
escodegen = require 'escodegen'
56

67
Language = require './language'
@@ -41,8 +42,8 @@ module.exports = class JavaScript extends Language
4142
return not _.isEqual(aAST.body, bAST.body)
4243
# Esprima couldn't parse either ASTs, so let's fall back to acorn_loose
4344
options = {locations: false, tabSize: 4, ecmaVersion: 5}
44-
aAST = acorn_loose.parse_dammit a, options
45-
bAST = acorn_loose.parse_dammit b, options
45+
aAST = acorn_loose.parse a, options
46+
bAST = acorn_loose.parse b, options
4647
unless aAST and bAST
4748
console.log "Couldn't even loosely parse; are you sure #{a} and #{b} are #{@name}?"
4849
return true
@@ -121,7 +122,7 @@ module.exports = class JavaScript extends Language
121122
ast = escodegen.attachComments ast, ast.comments, ast.tokens
122123
catch e
123124
console.log 'got error beautifying', e
124-
ast = acorn_loose.parse_dammit rawCode, {tabSize: 4, ecmaVersion: 5}
125+
ast = acorn_loose.parse rawCode, {tabSize: 4, ecmaVersion: 5}
125126
beautified = escodegen.generate ast, {comment: true, parse: esprima.parse}
126127
beautified
127128

@@ -152,7 +153,7 @@ module.exports = class JavaScript extends Language
152153
# Useful for parsing incomplete code as it is being written without giving up.
153154
# This should never throw an error and should always return some sort of AST, even if incomplete or empty.
154155
parseDammit: (code, aether) ->
155-
ast = acorn_loose.parse_dammit code, {locations: true, tabSize: 4, ecmaVersion: 5}
156+
ast = acorn_loose.parse code, {locations: true, tabSize: 4, ecmaVersion: 5}
156157

157158
if ast? and ast.body.length isnt 1
158159
ast.body = ast.body.slice(0,0)

package-lock.json

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
"@basicer/geoip-lite": "^1.1.6",
7474
"@sendgrid/mail": "^6.2.1",
7575
"@vimeo/player": "^2.9.1",
76+
"acorn-loose": "^8.0.1",
7677
"adobe-animate-parser": "github:codecombat/adobe-animate-parser#master",
7778
"ajv": "^6.10.0",
7879
"algoliasearch": "^3.13.1",
@@ -187,7 +188,6 @@
187188
"@storybook/addons": "^5.0.5",
188189
"@storybook/vue": "^5.0.5",
189190
"@vue/test-utils": "^1.0.0-beta.28",
190-
"acorn": "^6.1.1",
191191
"babel-cli": "^6.26.0",
192192
"babel-core": "^6.26.3",
193193
"babel-loader": "^7.1.5",

0 commit comments

Comments
 (0)