0
votes

(I revised this questions to be more informative at User idleberg's suggestion)

I'm using Atom editor. And I'm learning how to create package. I use atom's documentation and tutorial to learn how to customize the Atom. I used the 'wordcount' tutorial. (https://flight-manual.atom.io/hacking-atom/sections/package-word-count/).

I follow everything up to right before Basic Debugging section. I get the Unexpected token error. I couldn't figure out how to solve it. I did research on the net and all.

I just need to get that solved before I moved on to next section (Basic Debugging section.)

Here are info about my setup and error. Any help would be appreciated.

Atom: 1.32.1 x64

Electron: 2.0.9

OS: Mac OS X 10.14

Thrown From: zenkbarieswordcount package 0.0.0

Stack Trace

Failed to activate the zenkbarieswordcount package


At /Users/kellyboy/github/zenkbarieswordcount/lib/zenkbarieswordcount-view.js: Unexpected token (31:16)

SyntaxError: /Users/kellyboy/github/zenkbarieswordcount/lib/zenkbarieswordcount-view.js: Unexpected token (31:16)
}

Here is the code where the SyntaxError orginate. The first line is line 31.

31  setCount(count) {
32    const displayText = `There are ${count} words.`;
33    this.element.children[0].textContent = displayText;
34  }

here are the trace:

at Parser.pp.raise (/app.asar/node_modules/babylon/lib/parser/location.js:24:13)
at Parser.pp.unexpected (/app.asar/node_modules/babylon/lib/parser/util.js:82:8)
at Parser.pp.semicolon (/app.asar/node_modules/babylon/lib/parser/util.js:69:81)
at Parser.pp.parseExpressionStatement (/app.asar/node_modules/babylon/lib/parser/statement.js:427:8)
at Parser.parseExpressionStatement (/app.asar/node_modules/babylon/lib/plugins/flow.js:676:20)
at Parser.pp.parseStatement (/app.asar/node_modules/babylon/lib/parser/statement.js:142:21)
at Parser.parseStatement (/app.asar/node_modules/babylon/lib/plugins/flow.js:655:22)
at Parser.pp.parseTopLevel (/app.asar/node_modules/babylon/lib/parser/statement.js:30:21)
at Parser.parse (/app.asar/node_modules/babylon/lib/parser/index.js:70:17)
at Object.parse (/app.asar/node_modules/babylon/lib/index.js:45:50)
at Object.exports.default (/app.asar/node_modules/babel-core/lib/helpers/parse.js:36:18)
at File.parse (/app.asar/node_modules/babel-core/lib/transformation/file/index.js:574:40)
at File.parseCode (/app.asar/node_modules/babel-core/lib/transformation/file/index.js:691:20)
at /app.asar/node_modules/babel-core/lib/transformation/pipeline.js:167:12
at File.wrap (/app.asar/node_modules/babel-core/lib/transformation/file/index.js:639:16)
at Pipeline.transform (/app.asar/node_modules/babel-core/lib/transformation/pipeline.js:165:17)
at Object.e.compile (/Applications/Atom.app/Contents/Resources/app/static/<embedded>:11:573903)
at Object.compile (/Applications/Atom.app/Contents/Resources/app/static/<embedded>:11:570702)
at compileFileAtPath (/Applications/Atom.app/Contents/Resources/app/static/<embedded>:11:147501)
at Object.value [as .js] (/Applications/Atom.app/Contents/Resources/app/static/<embedded>:11:149898)
at Module.load (module.js:561:32)
at tryModuleLoad (module.js:504:12)
at Function.Module._load (module.js:496:3)
at Module.require (/app.asar/static/index.js:47:45)
at require (/Applications/Atom.app/Contents/Resources/app/static/<embedded>:11:145675)
at Object.<anonymous> (/Users/kellyboy/github/zenkbarieswordcount/lib/zenkbarieswordcount.js:7:32)
at Object.<anonymous> (/Users/kellyboy/github/zenkbarieswordcount/lib/zenkbarieswordcount.js:51:2)
at Module.get_Module._compile (/Applications/Atom.app/Contents/Resources/app/static/<embedded>:11:146385)
at Object.value [as .js] (/Applications/Atom.app/Contents/Resources/app/static/<embedded>:11:149932)
at Module.load (module.js:561:32)
at tryModuleLoad (module.js:504:12)
at Function.Module._load (module.js:496:3)
at Module.require (/app.asar/static/index.js:47:45)
at require (internal/module.js:11:18)
at customRequire (/Applications/Atom.app/Contents/Resources/app/static/<embedded>:1:620607)
at Package.requireMainModule (/Applications/Atom.app/Contents/Resources/app/static/<embedded>:11:2966969)

Commands I used that triggered the error

-0:04.1.0 zenkbarieswordcount:toggle (atom-pane.pane.active)

Mr GitHub repo for this code is: https://github.com/zenkbaries/zenkbarieswordcount

Non-Core Packages (that are installed on atom)

  • atom-beautify 0.33.4
  • busy-signal 1.4.3
  • intentions 1.1.5
  • jekyll 2.1.0
  • jekyll-syntax-highlighting 0.1.0
  • language-liquid 0.7.0
  • linter 2.2.0
  • linter-markdown 5.2.2
  • linter-stylelint 4.3.2
  • linter-ui-default 1.7.1
  • markdown-preview-kramdown 0.6.1
  • markdown-writer 2.10.3
  • platformio-ide-terminal 2.8.4
  • zenkbarieswordcount 0.0.0
1
You should post the relevant parts of your code, ideally as MCV. The error log shows errors in line 7, 32 and 57. What's in those lines? - idleberg
Thanks for you suggestion. I added more info (and cleaned and organized the questions bit better to make it more 'organized') - John Towery

1 Answers

0
votes

This looks like a simple syntax error. Without knowing the logic of your code, consider the following. You either need to move setCount() inside your class, or use the correct syntax to declare a function.

Example:

function setCount() {
  // your code
}

or, if you prefer using ES6 syntax, use an arrow function

setCount() => {
  // your code
}