-
-
Notifications
You must be signed in to change notification settings - Fork 8.9k
refactor(compiler): add separate transform for vbind shorthand #13438
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
fd7d6cf
refactor(compile): add independent transform for VBindShorthand
edison1105 503b4b5
fix(transform): validate property name for v-bind shorthand
edison1105 fbfc668
Merge branch 'main' into edison/refactor/vBindShorthand
edison1105 f51014a
Merge branch 'main' into edison/refactor/vBindShorthand
edison1105 e446096
Merge branch 'main' into edison/refactor/vBindShorthand
edison1105 ecd1d8b
chore: tweaks
edison1105 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
packages/compiler-core/src/transforms/transformVBindShorthand.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { camelize } from '@vue/shared' | ||
import { | ||
NodeTypes, | ||
type SimpleExpressionNode, | ||
createSimpleExpression, | ||
} from '../ast' | ||
import type { NodeTransform } from '../transform' | ||
import { ErrorCodes, createCompilerError } from '../errors' | ||
import { validFirstIdentCharRE } from '../utils' | ||
|
||
export const transformVBindShorthand: NodeTransform = (node, context) => { | ||
if (node.type === NodeTypes.ELEMENT) { | ||
for (const prop of node.props) { | ||
// same-name shorthand - :arg is expanded to :arg="arg" | ||
if ( | ||
prop.type === NodeTypes.DIRECTIVE && | ||
prop.name === 'bind' && | ||
!prop.exp | ||
) { | ||
const arg = prop.arg! | ||
if (arg.type !== NodeTypes.SIMPLE_EXPRESSION || !arg.isStatic) { | ||
// only simple expression is allowed for same-name shorthand | ||
context.onError( | ||
createCompilerError( | ||
ErrorCodes.X_V_BIND_INVALID_SAME_NAME_ARGUMENT, | ||
arg.loc, | ||
), | ||
) | ||
prop.exp = createSimpleExpression('', true, arg.loc) | ||
} else { | ||
const propName = camelize((arg as SimpleExpressionNode).content) | ||
if ( | ||
validFirstIdentCharRE.test(propName[0]) || | ||
// allow hyphen first char for https://github.com/vuejs/language-tools/pull/3424 | ||
propName[0] === '-' | ||
) { | ||
prop.exp = createSimpleExpression(propName, false, arg.loc) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.