From e37ea2c1f60aeb9ccba23e49f62b86f98808cf7b Mon Sep 17 00:00:00 2001 From: Christopher Chedeau Date: Tue, 23 May 2017 12:33:18 -0700 Subject: [PATCH] Add expression node in TSAsExpression (#1675) This lets the comment traversal code discover it --- src/typescript-ast-nodes.js | 5 ++++- .../__snapshots__/jsfmt.spec.js.snap | 12 ++++++++++++ tests/typescript_comments/jsfmt.spec.js | 1 + tests/typescript_comments/types.ts | 3 +++ 4 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 tests/typescript_comments/__snapshots__/jsfmt.spec.js.snap create mode 100644 tests/typescript_comments/jsfmt.spec.js create mode 100644 tests/typescript_comments/types.ts diff --git a/src/typescript-ast-nodes.js b/src/typescript-ast-nodes.js index caf446c0a..55eeca52f 100644 --- a/src/typescript-ast-nodes.js +++ b/src/typescript-ast-nodes.js @@ -123,7 +123,10 @@ module.exports = function(fork) { .field("typeAnnotation", def("TypeAnnotation")) .bases("TSSignature"); - def("TSAsExpression").bases("Expression"); + def("TSAsExpression") + .build("expression") + .field("expression", def("Node")) + .bases("Expression"); def("TSNamespaceExportDeclaration") .bases("Declaration") diff --git a/tests/typescript_comments/__snapshots__/jsfmt.spec.js.snap b/tests/typescript_comments/__snapshots__/jsfmt.spec.js.snap new file mode 100644 index 000000000..128bce0f8 --- /dev/null +++ b/tests/typescript_comments/__snapshots__/jsfmt.spec.js.snap @@ -0,0 +1,12 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`types.ts 1`] = ` +(() => { + // swallow error and fallback to using directory as path +}) as string[]; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +(() => { + // swallow error and fallback to using directory as path +}) as string[]; + +`; diff --git a/tests/typescript_comments/jsfmt.spec.js b/tests/typescript_comments/jsfmt.spec.js new file mode 100644 index 000000000..bc085c48c --- /dev/null +++ b/tests/typescript_comments/jsfmt.spec.js @@ -0,0 +1 @@ +run_spec(__dirname, { parser: "typescript" }); diff --git a/tests/typescript_comments/types.ts b/tests/typescript_comments/types.ts new file mode 100644 index 000000000..8e277783b --- /dev/null +++ b/tests/typescript_comments/types.ts @@ -0,0 +1,3 @@ +(() => { + // swallow error and fallback to using directory as path +}) as string[];