-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
feat(compiler-core): add openTagLoc
and closeTagLoc
to element ast node
#12928
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
base: main
Are you sure you want to change the base?
Changes from all commits
5f94ef9
e52d626
1c89b42
308c7f0
b4566c2
fb731b8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -78,6 +78,7 @@ export const defaultParserOptions: MergedParserOptions = { | |||||||||||||||||||
onWarn: defaultOnWarn, | ||||||||||||||||||||
comments: __DEV__, | ||||||||||||||||||||
prefixIdentifiers: false, | ||||||||||||||||||||
tagLocations: false, | ||||||||||||||||||||
} | ||||||||||||||||||||
|
||||||||||||||||||||
let currentOptions: MergedParserOptions = defaultParserOptions | ||||||||||||||||||||
|
@@ -146,6 +147,9 @@ const tokenizer = new Tokenizer(stack, { | |||||||||||||||||||
loc: getLoc(start - 1, end), | ||||||||||||||||||||
codegenNode: undefined, | ||||||||||||||||||||
} | ||||||||||||||||||||
if (currentOptions.tagLocations) { | ||||||||||||||||||||
currentOpenTag.openTagLoc = getLoc(start, end) | ||||||||||||||||||||
} | ||||||||||||||||||||
Comment on lines
+150
to
+152
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Set legacy alias for forward compatibility When the option is active you attach if (currentOptions.tagLocations) {
currentOpenTag.openTagLoc = getLoc(start, end)
+ // backwards compat
+ ;(currentOpenTag as any).tagLoc = currentOpenTag.openTagLoc
} This avoids breaking userland tools that already consume 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
|
||||||||||||||||||||
}, | ||||||||||||||||||||
|
||||||||||||||||||||
onopentagend(end) { | ||||||||||||||||||||
|
@@ -165,6 +169,9 @@ const tokenizer = new Tokenizer(stack, { | |||||||||||||||||||
} | ||||||||||||||||||||
for (let j = 0; j <= i; j++) { | ||||||||||||||||||||
const el = stack.shift()! | ||||||||||||||||||||
if (j === i && currentOptions.tagLocations) { | ||||||||||||||||||||
el.closeTagLoc = getLoc(start, end) | ||||||||||||||||||||
} | ||||||||||||||||||||
Comment on lines
171
to
+174
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same alias needed on close tag if (j === i && currentOptions.tagLocations) {
el.closeTagLoc = getLoc(start, end)
+ ;(el as any).tagLoc = el.openTagLoc // keep alias symmetrical
} 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
|
||||||||||||||||||||
onCloseTag(el, end, j < i) | ||||||||||||||||||||
} | ||||||||||||||||||||
break | ||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mismatch with test expectations – property should be
tagLoc
or an alias must be addedThe interface now exposes
openTagLoc
/closeTagLoc
, but the updated unit-test asserts against atagLoc
field.Unless an alias is added or the tests are updated, the type checker and the runtime equality check (
toStrictEqual
) will fail.Alternatively, rename the tests to use
openTagLoc
. Keep one consistent public field, or expose an alias – but make it deliberate.📝 Committable suggestion
🤖 Prompt for AI Agents