Skip to content

Commit 3629fc2

Browse files
Literal Computed Key Transform was grabbing info that didnt exist for all nodes before its safeguard
1 parent 178ea55 commit 3629fc2

File tree

6 files changed

+33
-3
lines changed

6 files changed

+33
-3
lines changed

src/transformers/literal-computed-keys.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ export default class LiteralComputedKeys extends Transform {
4141
walk.simple(program, {
4242
ObjectExpression(node: ObjectExpression) {
4343
for (const property of node.properties) {
44-
const [propertyStart]: Range = property.range as Range;
45-
const [valueStart]: Range = property.value.range as Range;
46-
4744
if (property.computed && property.key.type === 'Literal') {
45+
const [propertyStart]: Range = property.range as Range;
46+
const [valueStart]: Range = property.value.range as Range;
47+
4848
source.overwrite(
4949
propertyStart,
5050
valueStart,
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
let a=["put","add","delete","clear"];export function SpreadExpression(){return Object.assign({},a,{get:()=>console.log("get thing")})};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
let a=["put","add","delete","clear"];export function SpreadExpression(){return{...a,get:()=>console.log("get thing")}};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
var a=["put","add","delete","clear"];export function SpreadExpression(){return Object.assign({},a,{get:function(){return console.log("get thing")}})};
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const A = ['put', 'add', 'delete', 'clear'];
2+
3+
export function SpreadExpression(yep) {
4+
return {
5+
...A,
6+
get: (thing) => console.log('get thing'),
7+
}
8+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* Copyright 2020 The AMP HTML Authors. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS-IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import { generator } from '../generator';
18+
19+
generator('literal-computed-keys', 'spread-expression');

0 commit comments

Comments
 (0)