Skip to content
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

Added migrators for w-* attrs & code restructure #1190

Merged
merged 35 commits into from
Dec 14, 2018

Conversation

BhavinPatel04
Copy link
Contributor

Description

Added migrators for
w-idkey
w-for & for-keyfor:scoped
:key:scoped
w-preserveno-update
w-preserve-attrs:no-update

Restructured the code in taglibs/migrate

Checklist:

  • I have read the CONTRIBUTING document and have signed (or will sign) the CLA.
  • I have updated/added documentation affected by my changes.
  • I have added tests to cover my changes.

Copy link
Contributor

@DylanPiercey DylanPiercey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really awesome!

I left a few comments. Also we still need to remove the deprecated features from the codebase (outside of the migrate Taglib). Eg: w-preserve should be removed from https://github.com/marko-js/marko/blob/master/src/components/taglib/components-transformer.js#L70

values.split(",").forEach(val => {
const attrValue = el.getAttributeValue(val);
if (attrValue)
el.setAttributeValue(`${val}:no-update`, attrValue);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the else here we should still add ${val}:no-update with an empty attribute since the users intent may be to have the attribute be unset during the initial render and then mutated with JS later.

`The "${name}" attribute is deprecated. Please use "${newAttrName}" attribute instead. See: https://github.com/marko-js/marko/wiki/Deprecation:-w-*-Atrributes`
);

attr.name = newAttrName;
Copy link
Contributor

@DylanPiercey DylanPiercey Dec 11, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could be wrong but I think the if variants have their attribute values as a string and we will need to parse it as javascript a node.

@codecov
Copy link

codecov bot commented Dec 11, 2018

Codecov Report

Merging #1190 into master will decrease coverage by 0.04%.
The diff coverage is 93.9%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1190      +/-   ##
==========================================
- Coverage   90.62%   90.57%   -0.05%     
==========================================
  Files         321      328       +7     
  Lines       12209    12265      +56     
==========================================
+ Hits        11064    11109      +45     
- Misses       1145     1156      +11
Impacted Files Coverage Δ
src/compiler/Compiler.js 95.89% <ø> (-0.06%) ⬇️
...ib/TransformHelper/handleComponentPreserveAttrs.js 100% <ø> (ø) ⬆️
.../taglib/TransformHelper/handleComponentPreserve.js 77.61% <ø> (-16.42%) ⬇️
src/taglibs/migrate/common/w-on.js 100% <ø> (ø)
src/taglibs/migrate/common/w-for.js 100% <100%> (ø)
...onents/taglib/TransformHelper/assignComponentId.js 96.9% <100%> (+3.32%) ⬆️
src/taglibs/migrate/common/modifier-key.js 100% <100%> (ø)
src/compiler/Parser.js 97.28% <100%> (-0.03%) ⬇️
src/components/taglib/components-transformer.js 87.23% <100%> (-6.39%) ⬇️
src/taglibs/migrate/common/w-preserve-attrs.js 100% <100%> (ø)
... and 21 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2db165d...6ab95e3. Read the comment docs.

@coveralls
Copy link

coveralls commented Dec 11, 2018

Coverage Status

Coverage decreased (-0.05%) to 90.575% when pulling 6ab95e3 on BhavinPatel04:migrate-w-attr into 2db165d on marko-js:master.

const templateRoot = el.parentNode;
const walker = context.createWalker({
enter(node) {
if (node.type == "HtmlElement" && node.hasAttribute) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good but I think that we also need to check for type === "CustomTag". It would be simplest to only check for node.hasAttribute as only HTMLElement's and CustomTags's should have that method.

@@ -0,0 +1,16 @@
module.exports = function addIdScopedAttr(context, el, attrValue) {
const templateRoot = el.parentNode;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

el.parentNode is not the actual template root. We actually want to use context.root.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At this point, context.root is undefined. So took el.parentNode

const commonMigrators = fs
.readdirSync(path.join(__dirname, "./common/"))
.map(dir => require(`./common/${dir}`));
const getMigrators = d =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should revert this such that the common migrations is a flat structure (move all the w- stuff up a level).

As it stands right now all of these are in an event-handlers folder which is not totally accurate and I think unnecessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool. Let me structure it.

@DylanPiercey
Copy link
Contributor

Looks good, thanks for all the work on this 😄!

@DylanPiercey DylanPiercey merged commit e7bfb03 into marko-js:master Dec 14, 2018
@BhavinPatel04
Copy link
Contributor Author

Glad to be of help! :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants