-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Babel plugin for const -> let
- Loading branch information
1 parent
ca175d7
commit b245bc2
Showing
11 changed files
with
300 additions
and
0 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
build-system/babel-plugins/babel-plugin-const-transformer/index.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,35 @@ | ||
/** | ||
* Copyright 2020 The AMP HTML Authors. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS-IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
/** | ||
* Changes the | ||
* The above said variables are in src/mode.js file. | ||
* @param {Object} babelTypes | ||
* @return {!Object} | ||
*/ | ||
module.exports = function({types: t}) { | ||
return { | ||
visitor: { | ||
VariableDeclaration(path) { | ||
if (path.node.kind !== 'const') { | ||
return; | ||
} | ||
|
||
path.replaceWith(t.variableDeclaration('let', path.node.declarations)); | ||
}, | ||
}, | ||
}; | ||
}; |
40 changes: 40 additions & 0 deletions
40
...ns/babel-plugin-const-transformer/test/fixtures/transform-assertions/ignored-let/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,40 @@ | ||
/** | ||
* Copyright 2020 The AMP HTML Authors. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS-IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
let foo = true; | ||
let bar = 1; | ||
let baz = NaN; | ||
let yep = 'hello'; | ||
let another = {}; | ||
let array = []; | ||
|
||
function thing() { | ||
let foo = true; | ||
let bar = 1; | ||
let baz = NaN; | ||
let yep = 'hello'; | ||
let another = {}; | ||
let array = []; | ||
} | ||
|
||
thing: { | ||
let foo = true; | ||
let bar = 1; | ||
let baz = NaN; | ||
let yep = 'hello'; | ||
let another = {}; | ||
let array = []; | ||
} |
3 changes: 3 additions & 0 deletions
3
...abel-plugin-const-transformer/test/fixtures/transform-assertions/ignored-let/options.json
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 @@ | ||
{ | ||
"plugins": ["../../../../../babel-plugin-const-transformer"] | ||
} |
39 changes: 39 additions & 0 deletions
39
...s/babel-plugin-const-transformer/test/fixtures/transform-assertions/ignored-let/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,39 @@ | ||
/** | ||
* Copyright 2020 The AMP HTML Authors. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS-IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
let foo = true; | ||
let bar = 1; | ||
let baz = NaN; | ||
let yep = 'hello'; | ||
let another = {}; | ||
let array = []; | ||
|
||
function thing() { | ||
let foo = true; | ||
let bar = 1; | ||
let baz = NaN; | ||
let yep = 'hello'; | ||
let another = {}; | ||
let array = []; | ||
} | ||
|
||
thing: { | ||
let foo = true; | ||
let bar = 1; | ||
let baz = NaN; | ||
let yep = 'hello'; | ||
let another = {}; | ||
let array = []; | ||
} |
40 changes: 40 additions & 0 deletions
40
...ns/babel-plugin-const-transformer/test/fixtures/transform-assertions/ignored-var/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,40 @@ | ||
/** | ||
* Copyright 2020 The AMP HTML Authors. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS-IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
var foo = true; | ||
var bar = 1; | ||
var baz = NaN; | ||
var yep = 'hello'; | ||
var another = {}; | ||
var array = []; | ||
|
||
function thing() { | ||
var foo = true; | ||
var bar = 1; | ||
var baz = NaN; | ||
var yep = 'hello'; | ||
var another = {}; | ||
var array = []; | ||
} | ||
|
||
thing: { | ||
var foo = true; | ||
var bar = 1; | ||
var baz = NaN; | ||
var yep = 'hello'; | ||
var another = {}; | ||
var array = []; | ||
} |
3 changes: 3 additions & 0 deletions
3
...abel-plugin-const-transformer/test/fixtures/transform-assertions/ignored-var/options.json
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 @@ | ||
{ | ||
"plugins": ["../../../../../babel-plugin-const-transformer"] | ||
} |
39 changes: 39 additions & 0 deletions
39
...s/babel-plugin-const-transformer/test/fixtures/transform-assertions/ignored-var/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,39 @@ | ||
/** | ||
* Copyright 2020 The AMP HTML Authors. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS-IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
var foo = true; | ||
var bar = 1; | ||
var baz = NaN; | ||
var yep = 'hello'; | ||
var another = {}; | ||
var array = []; | ||
|
||
function thing() { | ||
var foo = true; | ||
var bar = 1; | ||
var baz = NaN; | ||
var yep = 'hello'; | ||
var another = {}; | ||
var array = []; | ||
} | ||
|
||
thing: { | ||
var foo = true; | ||
var bar = 1; | ||
var baz = NaN; | ||
var yep = 'hello'; | ||
var another = {}; | ||
var array = []; | ||
} |
40 changes: 40 additions & 0 deletions
40
...bel-plugin-const-transformer/test/fixtures/transform-assertions/should-transform/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,40 @@ | ||
/** | ||
* Copyright 2020 The AMP HTML Authors. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS-IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
const foo = true; | ||
const bar = 1; | ||
const baz = NaN; | ||
const yep = 'hello'; | ||
const another = {}; | ||
const array = []; | ||
|
||
function thing() { | ||
const foo = true; | ||
const bar = 1; | ||
const baz = NaN; | ||
const yep = 'hello'; | ||
const another = {}; | ||
const array = []; | ||
} | ||
|
||
thing: { | ||
const foo = true; | ||
const bar = 1; | ||
const baz = NaN; | ||
const yep = 'hello'; | ||
const another = {}; | ||
const array = []; | ||
} |
3 changes: 3 additions & 0 deletions
3
...plugin-const-transformer/test/fixtures/transform-assertions/should-transform/options.json
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 @@ | ||
{ | ||
"plugins": ["../../../../../babel-plugin-const-transformer"] | ||
} |
39 changes: 39 additions & 0 deletions
39
...el-plugin-const-transformer/test/fixtures/transform-assertions/should-transform/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,39 @@ | ||
/** | ||
* Copyright 2020 The AMP HTML Authors. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS-IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
let foo = true; | ||
let bar = 1; | ||
let baz = NaN; | ||
let yep = 'hello'; | ||
let another = {}; | ||
let array = []; | ||
|
||
function thing() { | ||
let foo = true; | ||
let bar = 1; | ||
let baz = NaN; | ||
let yep = 'hello'; | ||
let another = {}; | ||
let array = []; | ||
} | ||
|
||
thing: { | ||
let foo = true; | ||
let bar = 1; | ||
let baz = NaN; | ||
let yep = 'hello'; | ||
let another = {}; | ||
let array = []; | ||
} |
19 changes: 19 additions & 0 deletions
19
build-system/babel-plugins/babel-plugin-const-transformer/test/index.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,19 @@ | ||
/** | ||
* Copyright 2020 The AMP HTML Authors. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS-IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
const runner = require('@babel/helper-plugin-test-runner').default; | ||
|
||
runner(__dirname); |