Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
name: CI
on:
push:
branches:
- main
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
build:
name: test
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
tmp
.vscode
8 changes: 4 additions & 4 deletions lib/javascript/prefer-class-properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,17 @@ new Synvert.Rewriter("javascript", "prefer-class-properties", function () {
},
);

functions.forEach((func) => {
for (const func of functions) {
const source = indentCode(
`${this.mutationAdapter.getSource(func.left.name)} = ${this.mutationAdapter.getSource(func.right, {
fixIndent: true,
})}`,
tabSize,
);
insert(`\n\n${source.replace(/function ?/, "").replace(/\) {/, ") => {")}`, { at: "end" });
});
}

arrowFunctions.forEach((arrowFunction) => {
for (const arrowFunction of arrowFunctions) {
const source = indentCode(
`${this.mutationAdapter.getSource(arrowFunction.left.name)} = ${this.mutationAdapter.getSource(
arrowFunction.right,
Expand All @@ -103,7 +103,7 @@ new Synvert.Rewriter("javascript", "prefer-class-properties", function () {
tabSize,
);
insert(`\n\n${source}`, { at: "end" });
});
}
});

// handleChange() {}
Expand Down
8 changes: 4 additions & 4 deletions lib/react/prefer-class-properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,17 @@ new Synvert.Rewriter("react", "prefer-class-properties", () => {
},
);

functions.forEach((func) => {
for (const func of functions) {
const source = indentCode(
`${this.mutationAdapter.getSource(func.left.name)} = ${this.mutationAdapter.getSource(func.right, {
fixIndent: true,
})}`,
tabSize,
);
insert(`\n\n${source.replace(/function ?/, "").replace(/\) {/, ") => {")}`, { at: "end" });
});
}

arrowFunctions.forEach((arrowFunction) => {
for (const arrowFunction of arrowFunctions) {
const source = indentCode(
`${this.mutationAdapter.getSource(arrowFunction.left.name)} = ${this.mutationAdapter.getSource(
arrowFunction.right,
Expand All @@ -118,7 +118,7 @@ new Synvert.Rewriter("react", "prefer-class-properties", () => {
tabSize,
);
insert(`\n\n${source}`, { at: "end" });
});
}
});

// handleChange() {}
Expand Down
8 changes: 4 additions & 4 deletions lib/react/transform-class-components-to-functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ new Synvert.Rewriter("react", "transform-class-components-to-functions", () => {

// state = { key: value };
findNode(".PropertyDeclaration[name=state]", () => {
this.currentNode.initializer.properties.forEach((property) => {
for (const property of this.currentNode.initializer.properties) {
const name = property.name.escapedText;
const value = this.mutationAdapter.getSource(property.initializer);
functionBody.push(
Expand All @@ -64,7 +64,7 @@ new Synvert.Rewriter("react", "transform-class-components-to-functions", () => {
1,
),
);
});
}
});

// foo = () => {}
Expand All @@ -84,15 +84,15 @@ new Synvert.Rewriter("react", "transform-class-components-to-functions", () => {
if (lifecycleMethods.length > 0) {
functionBody.push(addLeadingSpaces("// Synvert TODO: convert lifecycle methods to useEffect by yourself"));
setUseEffect(currentFilePath);
lifecycleMethods.forEach((lifecycleMethod) => {
for (const lifecycleMethod of lifecycleMethods) {
const lines = this.mutationAdapter.getSource(lifecycleMethod, { fixIndent: true }).split("\n");
functionBody.push(
indentCode(
lines.map((line) => (line.length > 0 ? "// " + line : "//")).join("\n"),
1,
),
);
});
}
}

// render() {}
Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
},
"homepage": "https://github.com/synvert-hq/synvert-snippets-javascript#readme",
"devDependencies": {
"@synvert-hq/synvert-core": "^2.23.0",
"@synvert-hq/synvert-core": "^2.24.0",
"jest": "^27.0.6",
"mock-fs": "^5.4.0"
}
Expand Down
9 changes: 3 additions & 6 deletions test/bun/convert-jest-to-bun.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ describe(snippet, () => {
`;

assertConvert({
path: "test/foobar.spec.js",
path: "test/bun/convert-jest-to-bun.spec.js",
input,
output,
snippet,
helpers: ["helpers/add-import"],
});
});

Expand All @@ -39,11 +38,10 @@ describe(snippet, () => {
`;

assertConvert({
path: "test/foobar.spec.js",
path: "test/bun/convert-jest-to-bun.spec.js",
input,
output,
snippet,
helpers: ["helpers/add-import"],
});
});

Expand All @@ -66,11 +64,10 @@ describe(snippet, () => {
`;

assertConvert({
path: "test/foobar.spec.js",
path: "test/bun/convert-jest-to-bun.spec.js",
input,
output,
snippet,
helpers: ["helpers/add-import"],
});
});
});
13 changes: 1 addition & 12 deletions test/javascript/no-unused-imports.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ describe(snippet, () => {
const c = a() + b + x() + y();
`,
snippet,
helpers: ["helpers/remove-imports"],
});
});

Expand All @@ -36,7 +35,6 @@ describe(snippet, () => {
const c = b(x, y);
`,
snippet,
helpers: ["helpers/remove-imports"],
});
});

Expand All @@ -59,7 +57,6 @@ describe(snippet, () => {
const c = a(y);
`,
snippet,
helpers: ["helpers/remove-imports"],
});
});

Expand All @@ -77,7 +74,6 @@ describe(snippet, () => {
console.log(y);
`,
snippet,
helpers: ["helpers/remove-imports"],
});
});

Expand All @@ -92,7 +88,6 @@ describe(snippet, () => {
console.log(c);
`,
snippet,
helpers: ["helpers/remove-imports"],
});
});

Expand All @@ -108,7 +103,6 @@ describe(snippet, () => {
const c = a() + b;
`,
snippet,
helpers: ["helpers/remove-imports"],
});
});

Expand All @@ -123,7 +117,6 @@ describe(snippet, () => {
const c = a() + b;
`,
snippet,
helpers: ["helpers/remove-imports"],
});
});

Expand All @@ -138,7 +131,6 @@ describe(snippet, () => {
p.test();
`,
snippet,
helpers: ["helpers/remove-imports"],
});
});

Expand All @@ -152,7 +144,6 @@ describe(snippet, () => {
console.log("p");
`,
snippet,
helpers: ["helpers/remove-imports"],
});
});

Expand All @@ -167,7 +158,6 @@ describe(snippet, () => {
console.log(y);
`,
snippet,
helpers: ["helpers/remove-imports"],
});
});

Expand All @@ -194,8 +184,7 @@ describe(snippet, () => {
}
`,
snippet,
helpers: ["helpers/remove-imports"],
path: "code.jsx",
path: "javascript/no-unused-imports.jsx",
});
});
});
1 change: 0 additions & 1 deletion test/javascript/no-useless-constructor.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,5 @@ describe(snippet, () => {
input,
output,
snippet,
path: "code.js",
});
});
2 changes: 0 additions & 2 deletions test/javascript/prefer-class-properties.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ describe(snippet, () => {
input,
output,
snippet,
path: "code.jsx",
});
});

Expand Down Expand Up @@ -99,7 +98,6 @@ describe(snippet, () => {
input,
output,
snippet,
path: "code.jsx",
});
});
});
3 changes: 0 additions & 3 deletions test/react/add-autocomplete-attribute.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ describe(snippet, () => {
input,
output,
snippet,
path: "code.jsx",
});
});

Expand All @@ -38,7 +37,6 @@ describe(snippet, () => {
input,
output,
snippet,
path: "code.jsx",
});
});

Expand Down Expand Up @@ -71,7 +69,6 @@ describe(snippet, () => {
input,
output,
snippet,
path: "code.jsx",
});
});
});
4 changes: 2 additions & 2 deletions test/react/import-named-component.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe(snippet, () => {
input,
output,
snippet,
path: "code.jsx",
path: "react/import-named-component.jsx",
});
});

Expand All @@ -44,7 +44,7 @@ describe(snippet, () => {
input,
output,
snippet,
path: "code.jsx",
path: "react/import-named-component.jsx",
});
});
});
4 changes: 0 additions & 4 deletions test/react/import-prop-types.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ describe(snippet, () => {
input,
output,
snippet,
path: "code.jsx",
helpers: ["helpers/add-import", "helpers/remove-imports"],
});
});

Expand All @@ -35,8 +33,6 @@ describe(snippet, () => {
input,
output,
snippet,
path: "code.jsx",
helpers: ["helpers/add-import", "helpers/remove-imports"],
});
});
});
2 changes: 0 additions & 2 deletions test/react/prefer-class-properties.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,5 @@ describe(snippet, () => {
input,
output,
snippet,
subSnippets: ["javascript/no-useless-constructor"],
path: "code.jsx",
});
});
2 changes: 0 additions & 2 deletions test/react/remove-unused-react-imports.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,5 @@ describe(snippet, () => {
input,
output,
snippet,
helpers: ["helpers/remove-imports"],
path: "code.jsx",
});
});
Loading
Loading