Skip to content

Commit 5faad2f

Browse files
committed
Remove node.extra.shorthand
1 parent b595e4e commit 5faad2f

File tree

3 files changed

+11
-49
lines changed

3 files changed

+11
-49
lines changed

src/source.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,6 @@ export class Source {
6161
node.extra = { ...node.extra, raw, rawValue: value };
6262
break;
6363
}
64-
case 'ObjectProperty': {
65-
const { shorthand } = node as unknown as babel.ObjectProperty;
66-
if (shorthand) {
67-
node.extra = { ...node.extra, shorthand };
68-
}
69-
break;
70-
}
7164
}
7265

7366
return node;

src/transform-node.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,13 +216,15 @@ class Transformer extends Source {
216216
const shorthand = tKey.end < tKey.start || keyStart === valueStart;
217217
const value = transformChild<babel.Expression>(values[index]);
218218

219-
return createNode<babel.ObjectProperty>(
219+
return createNode<babel.ObjectPropertyNonComputed>(
220220
{
221221
type: 'ObjectProperty',
222222
key: tKey,
223223
value,
224224
shorthand,
225225
computed: false,
226+
// @ts-expect-error -- Missed in types
227+
method: false,
226228
},
227229
[tKey.start, valueEnd],
228230
[],

tests/helpers.ts

Lines changed: 8 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const babelParseOptions: babel.ParserOptions = {
99
'typescript', // NonNullAssert
1010
],
1111
ranges: true,
12+
attachComment: false,
1213
};
1314

1415
export const parseBabelExpression = (input: string) => {
@@ -32,51 +33,17 @@ export function massageAst(ast: any, parser: 'babel' | 'angular'): any {
3233
return ast.map((node) => massageAst(node, parser));
3334
}
3435

35-
if (parser === 'babel' && typeof ast.extra?.parenStart === 'number') {
36-
delete ast.extra.parenStart;
37-
}
38-
39-
// Not exists in types, but exists in node.
40-
if (ast.type === 'ObjectProperty') {
41-
if (ast.method !== undefined && ast.method !== false) {
42-
throw new Error(
43-
`Unexpected "method: ${ast.method}" in "ObjectProperty".`,
44-
);
36+
// We don't provide these
37+
if (parser === 'babel') {
38+
if (typeof ast.extra?.parenStart === 'number') {
39+
delete ast.extra.parenStart;
4540
}
46-
delete ast.method;
47-
48-
if (
49-
ast.shorthand &&
50-
ast.extra &&
51-
Object.keys(ast.extra).length === 1 &&
52-
ast.extra.shorthand
53-
) {
54-
delete ast.extra;
55-
}
56-
}
5741

58-
delete ast.loc;
42+
delete ast.loc;
43+
}
5944

6045
const massaged = Object.keys(ast).reduce((reduced: any, key) => {
61-
switch (key) {
62-
case 'trailingComments':
63-
// do nothing
64-
break;
65-
case 'extra': {
66-
const extra = massageAst(ast[key], parser);
67-
if (extra) {
68-
// we added a custom `parenEnd` field for positioning
69-
delete extra.parenEnd;
70-
if (Object.keys(extra).length !== 0) {
71-
reduced[key] = extra;
72-
}
73-
}
74-
break;
75-
}
76-
default:
77-
reduced[key] = massageAst(ast[key], parser);
78-
break;
79-
}
46+
reduced[key] = massageAst(ast[key], parser);
8047
return reduced;
8148
}, {});
8249

0 commit comments

Comments
 (0)