Closed jakobo closed 11 years ago
Yea, LinkJS expects a JavaScript source file. Your example is not a valid JavaScript statement. I'm hesitant to support it since there may be other corner cases that could be contradictory. I guess I could supply an API to specifically parse an expression but a much simpler solution is to wrap it in parenthesis. That should work whether it's a function or literal.
(function() {
return 'a';
})
('a')
If you want to parse an expression you can simply do:
linkjs.parse('(' + expression + ')')
That's a simple enough explanation for me. Thanks for the update. On Nov 6, 2012 5:49 PM, "Sebastian Markbåge" notifications@github.com wrote:
Yea, LinkJS expects a JavaScript source file. Your example is not a valid JavaScript statement. I'm hesitant to support it since there may be other corner cases that could be contradictory. I guess I could supply an API to specifically parse an expression but a much simpler solution is to wrap it in parenthesis. That should work whether it's a function or literal.
(function() { return 'a';})
('a')
If you want to parse en expression you can simply do:
linkjs.parse('(' + expression + ')')
— Reply to this email directly or view it on GitHubhttps://github.com/sebmarkbage/link.js/issues/4#issuecomment-10135489.
The tokenizer barfs on the expect("(") call, as it's already lex()-ed to ) in the string. Workaround is to rewrite the function with a function name, which gets past the lex problems.
Sample of us using our workaround: https://github.com/Jakobo/inject/blob/test_restructure/src/requirecontext.js#L327