react-sketchapp: GraphQL example won't run due to use of 'const' on El Capitan and lower

I am reporting an issue in the GraphQL example. After npm run render an error occurs in relation to the use of const, apparently due to “strict mode”. Disclaimer: I’m a long way on the design side of the design-dev fence - apologies if this is trivial.

Expected behavior: A sketch document rendered with live data from a GraphQL API.

Observed behavior: npm run render > profile-cards-gql@ render /Users/christianv/Projects/react-sketchapp/examples/profile-cards-graphql > skpm build --watch --run

🖨 Copied src/manifest.json in 6ms SyntaxError: Unexpected keyword 'const'. Const declarations are not supported in strict mode.. Plugin “react-sketchapp: Profile Cards w/ GraphQL”, line 6835: » const SuperInit = (0, _runtime.SuperCall)(NSStringFromSelector("init"), [], { type: "@" });

How to reproduce: Simply running npm run render after npm install

Sketch version: 43.2 (although irrelevant to this issue)

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 17 (1 by maintainers)

Most upvoted comments

v6.1.0

@mathieudutour @darknoon I’m late to the party 😃 but I’ve just hit the same problem with El Capitan users of JIRA Cloud for Sketch. I don’t think the problem is with arguments per se, but rather with the way Babel transforms the spread operator for arrays.

Babel reasonably assumes the func on https://github.com/darknoon/cocoascript-class/blob/006abf0c4c95604df36c83135d07dddd7ad64595/src/runtime.js#L7 is a normal JavaScript function, and transpiles it into some ES5 that calls func.apply(), which is undefined since it’s actually an MOBridgeSupportFunction, not a JS function.

To support earlier JavaScriptCore versions, we may have to write a more CocoaScript-friendly transform, or avoid using the spread operator – (MochaJsDelegate’s use of eval() makes a lot more sense to me now. 😃

I think the upstream bug is still in cocoascript-class (via sketch-polyfill-fetch via skpm) - there’s an open PR to fix it. @darknoon can we get this merged pls 🙏

https://github.com/darknoon/cocoascript-class/pull/1

skpm does transpile to ES5, it must be a dependency. We can add a custom .babelrc tho