Skip to content

Commit

Permalink
Merge 49971c1 into 02ab713
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanPiercey committed Dec 31, 2018
2 parents 02ab713 + 49971c1 commit 054ccb1
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 10 deletions.
5 changes: 4 additions & 1 deletion src/taglibs/migrate/all-tags/w-bind.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@ module.exports = function migrate(el, context) {
.then(shouldMigrate => {
if (shouldMigrate) {
el.removeAttribute("w-bind");
return helpers.run("componentFile", componentModule);
return helpers.run("componentFile", {
templateFile: context.filename,
componentFile: componentModule.filename
});
}
});
}
Expand Down
4 changes: 2 additions & 2 deletions test/migrate/fixtures/include-tag/snapshot-expected.marko
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ $ const ExampleD = undefined;
<!-- Import: with body -->
<${ExampleE}>
<div>Hi</div>
</${ExampleE}>
</>
<!-- Dynamic: basic -->
<if(typeof input.x === 'string')>${input.x}</if>
<else>
Expand All @@ -39,7 +39,7 @@ $ const ExampleD = undefined;
<else>
<${input.x}>
<div>Hi</div>
</${input.x}>
</>
</else>
<!-- Directive -->
<div>
Expand Down
12 changes: 6 additions & 6 deletions test/migrate/fixtures/layout-use/snapshot-expected.marko
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,29 @@ import ExampleD_1 from "./example-d.marko"
<!-- Import: basic -->
<${ExampleA}>
<div/>
</${ExampleA}>
</>
<!-- Import: with attributes -->
<${ExampleB} ...{
a: 1
} b=2>
<div/>
</${ExampleB}>
</>
<!-- Import: index -->
<${ExampleC}>
<div/>
</${ExampleC}>
</>
<!-- Import: name conflict -->
$ const ExampleD = undefined;
<${ExampleD_1}>
<div/>
</${ExampleD_1}>
</>
<!-- Dynamic: basic -->
<${input.x}>
<div/>
</${input.x}>
</>
<!-- Dynamic: with attributes -->
<${input.x} ...{
a: 1
} b=2>
<div/>
</${input.x}>
</>
5 changes: 5 additions & 0 deletions test/migrate/fixtures/w-bind-prompt-y/prompts.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,10 @@ module.exports = [
question:
"A widget file was discovered, would you like to migrate that as well?\nNote: widget migrations are not 100% safe and should be tested after migration.",
answer: true
},
{
question:
"Would you like to rename the component file?\nNote: Marko 4 automatically discovers these files based on the naming convention, you may be able to remove them from a browser.json file after this.",
answer: true
}
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"fileNames": {
"test/migrate/fixtures/w-bind-prompt-y/index.js": "test/migrate/fixtures/w-bind-prompt-y/template.component.js"
},
"dependentPaths": {}
}
5 changes: 5 additions & 0 deletions test/migrate/fixtures/widget-get-template-data/prompts.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,10 @@ module.exports = [
question:
"A widget file was discovered, would you like to migrate that as well?\nNote: widget migrations are not 100% safe and should be tested after migration.",
answer: true
},
{
question:
"Would you like to rename the component file?\nNote: Marko 4 automatically discovers these files based on the naming convention, you may be able to remove them from a browser.json file after this.",
answer: false
}
];
33 changes: 32 additions & 1 deletion test/migrate/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ if (!/^v6\..*/.test(process.version)) {
return currentPrompt.answer;
}
}).then(outputs => {
const byExtension = Object.entries(outputs)
const byExtension = Object.entries(outputs.fileContents)
.sort(([a], [b]) => a.localeCompare(b))
.reduce((r, [file, source]) => {
const ext = path.extname(file);
Expand All @@ -55,6 +55,29 @@ if (!/^v6\..*/.test(process.version)) {
return r;
}, {});

if (
!isEmpty(outputs.fileNames) ||
!isEmpty(outputs.dependentPaths)
) {
snapshot(
JSON.stringify(
{
fileNames: outputs.fileNames,
dependentPaths: outputs.dependentPaths
},
null,
2
).replace(
/"(\/[^"]+)"/g,
(_, file) => `"${path.relative(CWD, file)}"`
),
{
ext: ".json",
name: "updated-path-snapshot"
}
);
}

Object.entries(byExtension).forEach(([ext, files]) => {
snapshot(files.join("\n\n"), {
ext,
Expand All @@ -77,3 +100,11 @@ function toComment(ext, str) {
return `# ${str}`;
}
}

function isEmpty(obj) {
for (const _ in obj) {
return false;
}

return true;
}

0 comments on commit 054ccb1

Please sign in to comment.