-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
207 additions
and
33 deletions.
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
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
4 changes: 4 additions & 0 deletions
4
...emod/test/fixtures/convert-default-export-objects-to-named-exports/computed-keys.input.js
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,4 @@ | ||
export default { | ||
foo: 'bar', | ||
[baz]: 'qux', | ||
}; |
4 changes: 4 additions & 0 deletions
4
...mod/test/fixtures/convert-default-export-objects-to-named-exports/computed-keys.output.js
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,4 @@ | ||
export default { | ||
foo: 'bar', | ||
[baz]: 'qux', | ||
}; |
3 changes: 3 additions & 0 deletions
3
...test/fixtures/convert-default-export-objects-to-named-exports/invalid-identifier.input.js
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,3 @@ | ||
export default { | ||
'foo-bar': 'baz', | ||
}; |
3 changes: 3 additions & 0 deletions
3
...est/fixtures/convert-default-export-objects-to-named-exports/invalid-identifier.output.js
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,3 @@ | ||
export default { | ||
'foo-bar': 'baz', | ||
}; |
7 changes: 7 additions & 0 deletions
7
...ify-codemod/test/fixtures/convert-default-export-objects-to-named-exports/method.input.js
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,7 @@ | ||
export default { | ||
foo: 'bar', | ||
baz() { | ||
return 'qux'; | ||
}, | ||
fuzz: () => buzz, | ||
}; |
9 changes: 9 additions & 0 deletions
9
...fy-codemod/test/fixtures/convert-default-export-objects-to-named-exports/method.output.js
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,9 @@ | ||
export const foo = 'bar'; | ||
|
||
export function baz() { | ||
return 'qux'; | ||
}; | ||
|
||
export function fuzz() { | ||
return buzz; | ||
}; |
5 changes: 5 additions & 0 deletions
5
...codemod/test/fixtures/convert-default-export-objects-to-named-exports/non-object.input.js
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,5 @@ | ||
export default [1, 2, 3]; | ||
|
||
export const foo = { | ||
bar: 'baz', | ||
}; |
5 changes: 5 additions & 0 deletions
5
...odemod/test/fixtures/convert-default-export-objects-to-named-exports/non-object.output.js
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,5 @@ | ||
export default [1, 2, 3]; | ||
|
||
export const foo = { | ||
bar: 'baz', | ||
}; |
6 changes: 6 additions & 0 deletions
6
...opify-codemod/test/fixtures/convert-default-export-objects-to-named-exports/this.input.js
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,6 @@ | ||
export default { | ||
foo: 'bar', | ||
baz() { | ||
return this.foo; | ||
}, | ||
}; |
6 changes: 6 additions & 0 deletions
6
...pify-codemod/test/fixtures/convert-default-export-objects-to-named-exports/this.output.js
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,6 @@ | ||
export default { | ||
foo: 'bar', | ||
baz() { | ||
return this.foo; | ||
}, | ||
}; |
2 changes: 1 addition & 1 deletion
2
...-codemod/test/fixtures/convert-default-export-objects-to-named-exports/variables.input.js
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
export default { | ||
dee: ta, | ||
sho: foo | ||
'sho': foo | ||
}; |
1 change: 1 addition & 0 deletions
1
packages/shopify-codemod/test/fixtures/remove-empty-statements/basic.input.js
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 @@ | ||
export function foo() {}; |
1 change: 1 addition & 0 deletions
1
packages/shopify-codemod/test/fixtures/remove-empty-statements/basic.output.js
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 @@ | ||
export function foo() {} |
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
8 changes: 8 additions & 0 deletions
8
packages/shopify-codemod/test/transforms/remove-empty-statements.test.js
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,8 @@ | ||
import 'test-helper'; | ||
import removeEmptyStatements from 'remove-empty-statements'; | ||
|
||
describe('removeEmptyStatements', () => { | ||
it('removes empty statements', () => { | ||
expect(removeEmptyStatements).to.transform('remove-empty-statements/basic'); | ||
}); | ||
}); |
4 changes: 2 additions & 2 deletions
4
packages/shopify-codemod/transform-cli/templates/test-suite.js.template
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 |
---|---|---|
@@ -1,8 +1,8 @@ | ||
import 'test-helper'; | ||
import transform from '__DASHERIZED_NAME__'; | ||
import __CAMELIZED_NAME__ from '__DASHERIZED_NAME__'; | ||
|
||
describe('__CAMELIZED_NAME__', () => { | ||
it('CHANGE THIS', () => { | ||
expect(transform).to.transform('__DASHERIZED_NAME__/basic'); | ||
expect(__CAMELIZED_NAME__).to.transform('__DASHERIZED_NAME__/basic'); | ||
}); | ||
}); |
24 changes: 11 additions & 13 deletions
24
packages/shopify-codemod/transforms/constant-function-expression-to-statement.js
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 |
---|---|---|
@@ -1,27 +1,25 @@ | ||
import {containsThisExpression, isFunctionExpression, getBlockStatementFromFunction} from './utils'; | ||
|
||
export default function constantFunctionValueToStatement({source}, {jscodeshift: j}, {printOptions = {}}) { | ||
return j(source) | ||
.find(j.VariableDeclaration, (path) => j.match(path, { | ||
kind: 'const', | ||
declarations: [{ | ||
type: 'VariableDeclarator', | ||
init: {type: (type) => type === 'FunctionExpression' || type === 'ArrowFunctionExpression'}, | ||
init: isFunctionExpression, | ||
}], | ||
}) && (path.declarations[0].init.type !== 'ArrowFunctionExpression' || j(path).find(j.ThisExpression).size() === 0)) | ||
}) && (path.declarations[0].init.type !== 'ArrowFunctionExpression' || !containsThisExpression(path))) | ||
.replaceWith((path) => { | ||
const declarator = path.node.declarations[0]; | ||
const {init: {params, generator, expression}} = declarator; | ||
let {init: {body}} = declarator; | ||
if (!j.BlockStatement.check(body)) { | ||
body = j.blockStatement([j.returnStatement(body)]); | ||
} | ||
const {init: {params, generator}} = declarator; | ||
|
||
return j.functionDeclaration( | ||
declarator.id, | ||
params, | ||
body, | ||
generator, | ||
expression | ||
); | ||
declarator.id, | ||
params, | ||
getBlockStatementFromFunction(declarator.init), | ||
generator, | ||
false, | ||
); | ||
}) | ||
.toSource(printOptions); | ||
} |
57 changes: 47 additions & 10 deletions
57
packages/shopify-codemod/transforms/convert-default-export-objects-to-named-exports.js
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
6 changes: 6 additions & 0 deletions
6
packages/shopify-codemod/transforms/remove-empty-statements.js
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,6 @@ | ||
export default function removeEmptyStatements({source}, {jscodeshift: j}, {printOptions = {quote: 'single'}}) { | ||
return j(source) | ||
.find(j.EmptyStatement) | ||
.replaceWith() | ||
.toSource(printOptions); | ||
} |
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