Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can't build cocoascript in js file #106

Closed
ziven27 opened this issue Jan 4, 2018 · 5 comments
Closed

can't build cocoascript in js file #106

ziven27 opened this issue Jan 4, 2018 · 5 comments
Labels

Comments

@ziven27
Copy link

ziven27 commented Jan 4, 2018

src/my-command.js

var writeTextToFile = function(text, filePath) {
  var t = [NSString stringWithFormat: @ "%@", text],
      f = [NSString stringWithFormat: @ "%@", filePath];
      return [t writeToFile: f atomically: true encoding: NSUTF8StringEncoding error: nil];
}

export default function(context) {

}

I can't build this file in 'npm run start'

error Error while building my-command.js
./src/my-command.js
Module build failed: SyntaxError: Unexpected token, expected , (3:22)
@mathieudutour
Copy link
Member

yes, cocoascript is a mistake and should have never been allowed. It breaks all the JS tooling. Use the JS syntax instead:

var writeTextToFile = function(text, filePath) {
  var t = NSString.stringWithFormat("%@", text)
      f = NSString.stringWithFormat("%@", filePath);
      return t.writeToFile_atomically_encoding_error(f, true, NSUTF8StringEncoding, null)
}

export default function(context) {

}

@ziven27
Copy link
Author

ziven27 commented Jan 8, 2018

ok thx.
but I don't known how to write a string into file.text in JS syntax.

where can I find the JS syntax? When I got a cocoascript.

@mathieudutour
Copy link
Member

the example i wrote doesn't work?

More generally, there are only 2 "rules":

  • All colons are converted to underscores (the latest underscore is optional).
  • Each component of the selector is concatenated into a single string with no separation.

http://developer.sketchapp.com/guides/cocoascript/

@ziven27
Copy link
Author

ziven27 commented Jan 8, 2018

gotcha! thank you so much

@hummatli
Copy link

hummatli commented Aug 6, 2019

Thx, @mathieudutour.

The code you wrote is correct :) except for one comma between variable declarations. I added it.

  var t = NSString.stringWithFormat("%@", text),
      f = NSString.stringWithFormat("%@", filePath);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants