skpm / sketch-dev-tools

See your plugin logs, inspect the state of Sketch documents, explore actions, and more!

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SyntaxError: Unexpected keyword 'const'.

tanem opened this issue · comments

Hi there,

I'm using Sketch 49 (51002) on El Capitan, and I'm getting the following error when trying to open this plugin:

8/03/18 11:41:53.415 AM Show DevTools (Sketch)[88136]: SyntaxError: Unexpected keyword 'const'. Const declarations are not supported in strict mode..
Plugin “show-debugger”, line 1:

I'm a bit of a novice with how Sketch plugins are set up... is this an issue with JavaScriptCore? My Safari version is at latest (11.0.3) and my system Node version is at 9.7.1.

I guess I could fork the repo and try to build a version of the plugin that transpiles things... but don't want to go there unless I really have to.

Any ideas?

Yeah, it's an issue with JavaScriptCore on El Capitan. The issue with transpiling is that it's going to use arguments and that breaks when running functions across the bridge

Thanks @mathieudutour. So where does that leave us - is the best option to fork the repo and, say, flip the const declarations back to var? I'm wondering who else may be hitting this issue, in which case a fork might be useful to others as well.

Well that’s not the only issue, there are a bunch more, look at the darknoon/cocoascript-class repo

Ok thanks for pointing me in that direction, can see what the issues are now.

Managed to get the window to open after manually transpiling in sketch-dev-tools/dev-tools.sketchplugin/Contents/Sketch/show-debugger.js:

  • , ...x] to ].concat(x)
  • (x) => { to function (x) {
  • (x) => y to function (x) {return y}
  • return func.apply(this, [x, y, ...arguments]) with:
// relevant bundled non-transpiled file: ./node_modules/cocoascript-class/lib/runtime.js
var n = arguments.length
    return n==0? func(structPtr, selector)
      : n==1? func(structPtr, selector, arguments[0])
      : n==2? func(structPtr, selector, arguments[0], arguments[1])
      : n==3? func(structPtr, selector, arguments[0], arguments[1], arguments[2])
      : n==4? func(structPtr, selector, arguments[0], arguments[1], arguments[2], arguments[3])
      : n==5? func(structPtr, selector, arguments[0], arguments[1], arguments[2], arguments[3], arguments[4]) // etc
      : log('SuperCall too many args ' + n)

Looks neat!

image

But yeah, there is some issue as noted before, doesn't finish loading and no logs (skpm log -f -n 10). Would be great to have some os check or big warning pointing to this issue to avoid more wasted time :) Would love to use this!

Also. cmd-alt dragging the plugin to the plugins folder, alt. ln -s "$(pwd)/dev-tools.sketchplugin" ~/"Library/Application Support/com.bohemiancoding.sketch3/Plugins"/ makes reloading much faster. Also defaults write ~/Library/Preferences/com.bohemiancoding.sketch3.plist AlwaysReloadScript -bool YES doesn't seem to work for me, still have to restart Sketch between edits.

Linked issue: darknoon/cocoascript-class#2


Update: Actions tab seems to be working!
image

The logs only work on Sketch 50+ and the hot reloading doesn't work because it's a long running script.

I think I'll close this issue as a "won't fix"

Solved it!

Until the PR to @darknoon is merged, a workaround for those not running the latest OSX...:

  • git clone git@github.com:skpm/sketch-dev-tools.git
  • git clone git@github.com:LeonardPauli/cocoascript-class.git
  • (cd cocoascript-class && npm i && npm link)
  • cd sketch-dev-tools && npm i && npm link cocoascript-class
  • npm run build + install the plugin, or just open sketch + npm run start

Alternatively, just install pre-built: dev-tools-with-older-jsc-support.sketchplugin.zip (as of 3 June, v0.6.0)

Looks like everything is working somewhat properly! (network tab says coming soon) Thanks for the plugin, looking forward to fix mine now XD

Ps. I'm running v50.2; long running script - thx, should have though of that!; What is the workflow then?... nvm, found skpm/skpm#142