-
Notifications
You must be signed in to change notification settings - Fork 648
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
Await tag #312
Merged
Merged
Await tag #312
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
6725683
deprecate <async-fragment> replace with <await>
mlrawlings 8d18b04
fix bad grammar due to word replacement
mlrawlings b54cd57
more wording improvements
mlrawlings 09111f2
remove unnecessary code
mlrawlings 22e81c9
remove references to async-fragments in the docs
mlrawlings 4c9ceb0
remove and rename references to <async-fragment> in the code (except …
mlrawlings b153ac1
more documentation updates related to async-fragment => await
mlrawlings b3c3c56
additional tests
mlrawlings ef29452
don't use split, use a regex match
mlrawlings 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 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 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,53 @@ | ||
'use strict'; | ||
|
||
var newTags = { | ||
'async-fragment':'await', | ||
'async-fragments':'await-reorderer', | ||
'async-fragment-placeholder':'await-placeholder', | ||
'async-fragment-timeout':'await-timeout', | ||
'async-fragment-error':'await-error' | ||
}; | ||
|
||
module.exports = function transform(oldNode, context) { | ||
var oldTag = oldNode.tagName; | ||
var newTag = newTags[oldTag]; | ||
var provider; | ||
var varName; | ||
var argument; | ||
|
||
context.data = context.data || {}; | ||
context.data.warnings = context.data.warnings || {}; | ||
|
||
if(!context.data.warnings[oldTag]) { | ||
console.warn('The <'+oldTag+'> tag is deprecated. Please use <'+newTag+'> instead.'); | ||
context.data.warnings[oldTag] = true; | ||
} | ||
|
||
if(oldTag == 'async-fragment'/* new: <await> */) { | ||
// need to convert data-provider and var attributes | ||
// to an argument: <await(var from dataProvider)> | ||
varName = oldNode.getAttributeValue('var').value; | ||
provider = oldNode.getAttributeValue('data-provider').toString(); | ||
argument = varName + ' from ' + provider; | ||
|
||
// now remove the attributes | ||
oldNode.removeAttribute('var'); | ||
oldNode.removeAttribute('data-provider'); | ||
} | ||
|
||
if(oldTag == 'async-fragments'/* new: <await-reorderer> */) { | ||
// all this tag ever did was handling of client reordering | ||
// we'll remove the attribute as that's all this new tag does | ||
oldNode.removeAttribute('client-reorder'); | ||
} | ||
|
||
var newNode = context.createNodeForEl( | ||
newTag, | ||
oldNode.getAttributes(), | ||
argument | ||
); | ||
|
||
newNode.body = oldNode.body; | ||
newNode.body.node = newNode; | ||
oldNode.replaceWith(newNode); | ||
}; |
This file contains 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
File renamed without changes.
This file contains 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
File renamed without changes.
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.
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.
Using split is not a good idea since there is very small chance
from
might appear in the expression. I would use a regular expression that is rooted on the side of the variable name to separate out the variable name from the potentially complex expression: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.
For some reason I was thinking that split with a string argument would only split on the first instance it found, but that's definitely not the case. Once we figure out
as
vsfrom
I'll change it to use a rooted regex.