Comments (8)
@wycats brought up an interesting idea, to get better line numbers short of the complexity of sourcemaps you can just get smarter about inserting spaces and newlines. For example, a macro that emits a function with line breaks:
macro m {
case => {
function foo() {
return x + 2;
}
}
}
m
could be expanded to:
function foo() { return x + 2; }
This should be easy to do in the expander, just set the lineNumber
on each token emitted by a macro expansion to the lineNumber
of the invoking macro token (m
above).
Going the other way (macro invocation is longer than emitted JS) should be pretty simple:
macro aLongMacroName {
case => {42}
}
aLongMacroName + 24;
could use loc
to expand to:
42 + 24;
Unfortunately, ASI complicates the process a bit.
macro m {
case => {
return
[1,2,3]
}
}
m
If we naively expand this while collapsing lines:
return [1,2,3]
we get the wrong result. So the line collapsing needs to be grammar aware (I'm guessing minifiers do the same thing) and insert semicolons at the appropriate points:
return; [1,2,3]
But we still have a problem: return
might be a macro. We can't make decisions about the grammar until after full expansion but by then we've lost too much information.
So maybe we can tag each token emitted from a macro with a "potential" collapse line number and do proper semicolon insertion after all macros have been expanded and we have the "real" grammar information?
from sweet-core.
is there any more thought on this?
from sweet-core.
This is happening very soon. I'm expecting sourcemaps to land in the next few weeks.
from sweet-core.
Initial work checked in with 6c4c40c. Still rough atm but sjs -o outfile.js infile.sjs --sourcemap
will create outfile.js.map
.
from sweet-core.
Major fixes for this are in commit 3336448 and PR #127. Unless there are any bugs I don't know about sourcemaps should be usable now.
from sweet-core.
Should be mostly working with 4f15b50.
from sweet-core.
Any documentation on that? Sadly, the wiki entry is still red. :/
from sweet-core.
Use the --sourcemap
flag on sjs
. Thanks for pointing out the red wiki link, just made it blue :)
from sweet-core.
Related Issues (20)
- How to import macros by one macro, maybe we can name it meta-macro? HOT 2
- Syntactical feasibility/implementation advice HOT 12
- Updating codegen HOT 1
- Errors with valid ES6 import syntax HOT 3
- Hygiene broken in template literals that use interpolation HOT 1
- Can you make a "symbol" macro? HOT 5
- Is this repo being maintained?
- Operator precedence not respected HOT 2
- Question: best way to include sweet.js in my project HOT 4
- Basic examples not working HOT 6
- Import not working HOT 6
- Compile to JavaScript without semi colons HOT 4
- [Question] How does sweet.compile or sweet.parse function works? HOT 1
- Extend native JS / TS objects in a safe way HOT 1
- Not renaming variables inside parens HOT 3
- Wrong precedence for operator HOT 1
- is this still repo active? we need es macros HOT 1
- [Question] How to render a dynamic expression inside a function?
- Let's fork the project! HOT 4
- Variable binding (hygiene, gensym) not working in 2-level macros HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sweet-core.