Skip to content
This repository was archived by the owner on Jan 19, 2019. It is now read-only.

Breaking: Handle TSModuleDeclaration and refactor (fixes #371) #372

Merged
merged 1 commit into from
Aug 21, 2017
Merged
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
16 changes: 16 additions & 0 deletions lib/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,10 @@ module.exports = function convert(config) {
result.const = true;
handledModifierIndices[i] = true;
break;
case SyntaxKind.DeclareKeyword:
result.declare = true;
handledModifierIndices[i] = true;
break;
default:
}
}
Expand Down Expand Up @@ -2072,6 +2076,18 @@ module.exports = function convert(config) {
break;
}

case SyntaxKind.ModuleDeclaration: {
Object.assign(result, {
type: AST_NODE_TYPES.TSModuleDeclaration,
id: convertChild(node.name)
});
applyModifiersToResult(node.modifiers);
if (node.body) {
result.body = convertChild(node.body);
}
break;
}

default:
deeplyCopy();
}
Expand Down
4 changes: 4 additions & 0 deletions tests/ast-alignment/spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,10 @@ const fixturePatternsToTest = [
// "typescript/namespaces-and-modules/ambient-module-declaration-with-import.src.ts",
// "typescript/namespaces-and-modules/declare-namespace-with-exported-function.src.ts",
// "typescript/namespaces-and-modules/module-with-default-exports.src.ts",

/**
* Requires fix in https://github.com/babel/babylon/pull/684
*/
// "typescript/namespaces-and-modules/shorthand-ambient-module-declaration.src.ts"

];
Expand Down
148 changes: 47 additions & 101 deletions tests/lib/__snapshots__/typescript.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -60668,36 +60668,8 @@ Object {
],
"type": "TSModuleBlock",
},
"loc": Object {
"end": Object {
"column": 1,
"line": 3,
},
"start": Object {
"column": 0,
"line": 1,
},
},
"modifiers": Array [
Object {
"loc": Object {
"end": Object {
"column": 7,
"line": 1,
},
"start": Object {
"column": 0,
"line": 1,
},
},
"range": Array [
0,
7,
],
"type": "TSDeclareKeyword",
},
],
"name": Object {
"declare": true,
"id": Object {
"loc": Object {
"end": Object {
"column": 29,
Expand All @@ -60716,6 +60688,16 @@ Object {
"type": "Literal",
"value": "i-use-things",
},
"loc": Object {
"end": Object {
"column": 1,
"line": 3,
},
"start": Object {
"column": 0,
"line": 1,
},
},
"range": Array [
0,
56,
Expand Down Expand Up @@ -61165,36 +61147,8 @@ Object {
],
"type": "TSModuleBlock",
},
"loc": Object {
"end": Object {
"column": 1,
"line": 3,
},
"start": Object {
"column": 0,
"line": 1,
},
},
"modifiers": Array [
Object {
"loc": Object {
"end": Object {
"column": 7,
"line": 1,
},
"start": Object {
"column": 0,
"line": 1,
},
},
"range": Array [
0,
7,
],
"type": "TSDeclareKeyword",
},
],
"name": Object {
"declare": true,
"id": Object {
"loc": Object {
"end": Object {
"column": 20,
Expand All @@ -61212,6 +61166,16 @@ Object {
],
"type": "Identifier",
},
"loc": Object {
"end": Object {
"column": 1,
"line": 3,
},
"start": Object {
"column": 0,
"line": 1,
},
},
"range": Array [
0,
84,
Expand Down Expand Up @@ -61881,17 +61845,7 @@ Object {
],
"type": "TSModuleBlock",
},
"loc": Object {
"end": Object {
"column": 1,
"line": 6,
},
"start": Object {
"column": 0,
"line": 1,
},
},
"name": Object {
"id": Object {
"loc": Object {
"end": Object {
"column": 12,
Expand All @@ -61910,6 +61864,16 @@ Object {
"type": "Literal",
"value": "foo",
},
"loc": Object {
"end": Object {
"column": 1,
"line": 6,
},
"start": Object {
"column": 0,
"line": 1,
},
},
"range": Array [
0,
112,
Expand Down Expand Up @@ -62410,36 +62374,8 @@ exports[`typescript fixtures/namespaces-and-modules/shorthand-ambient-module-dec
Object {
"body": Array [
Object {
"loc": Object {
"end": Object {
"column": 32,
"line": 1,
},
"start": Object {
"column": 0,
"line": 1,
},
},
"modifiers": Array [
Object {
"loc": Object {
"end": Object {
"column": 7,
"line": 1,
},
"start": Object {
"column": 0,
"line": 1,
},
},
"range": Array [
0,
7,
],
"type": "TSDeclareKeyword",
},
],
"name": Object {
"declare": true,
"id": Object {
"loc": Object {
"end": Object {
"column": 31,
Expand All @@ -62458,6 +62394,16 @@ Object {
"type": "Literal",
"value": "hot-new-module",
},
"loc": Object {
"end": Object {
"column": 32,
"line": 1,
},
"start": Object {
"column": 0,
"line": 1,
},
},
"range": Array [
0,
32,
Expand Down