-
-
Notifications
You must be signed in to change notification settings - Fork 597
Template interpolation service and template sourcemap #1215
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
Conversation
Just occurred to me that |
@octref walkTSNode(sourceFile, newSourceFile, (from, to) => {
if (from.pos === -1 || from.end === -1) {
return;
}
sourceMapNodes.push({
from: {
start: from.pos,
end: from.end
},
to: {
start: to.pos,
end: to.end
}
}
});
I think we need to do this. In any cases, there are variables without |
Does that get all declared identifiers in a source file? I'm not sure about that because we need to handle scope changes by v-for and v-slot. |
NVM, actually |
Some explorations...
/**
* Gets a custom text range to use when emitting source maps.
*/
function getSourceMapRange(node) {
var emitNode = node.emitNode;
return (emitNode && emitNode.sourceMapRange) || node;
}
/**
* Sets a custom text range to use when emitting source maps.
*/
function setSourceMapRange(node, range) {
getOrCreateEmitNode(node).sourceMapRange = range;
return node;
} Here's a rough plan:
So for
|
OK, just two more test to fix then we are good.
@ktsn Why did you choose |
|
I remember this is to avoid |
@ktsn Fixed all tests! Thanks a lot for reviewing. |
High level changes:
position
is inside directive interpolations (previously only detect {{}}), and add teststransformTemplate
andpreprocess
generate thefrom
andto
part of the sourcemapstemplateMode
now has 2 parts,htmlMode
(old html functionalities) andinterpolationMode
(new interpolation functionalities)serviceHost
and make it available tointerpolationMode
interpolationMode
can map back requests / responsesSmal changes:
Todo:
interpolationMode
(this is rather straightforward once sourcemap is correct)How source map works:
ThisKeyword
created, add afrom
source map nodets.createPrinter
and re-parsed into SourceFilethis.
access and addto
source map nodeProblem & Questions for the sourcemap:
foo
,foo()
,foo(5)
,foo(bar)
,foo = 5
, the mapping becomes harder and harder. If I only map thethis
access, diagnostics errors might exist on5
which is not mapped...Instead of trying to map on each
this
level, we try to map onts.Expression
levelInstead of the old map format like this (which don't work quite well once you need to map
foo(5)
tothis.foo(5)
, since you have tokens before and after thefoo
)Create a new sourcemap like so:
This ensures that we can handle cases when initial interpolations have the
this.
inside it too.I don't know if we should try to generalize the source map work. It's so tedious that I think Vue template compiler should have a canonical version that everyone can depend upon.