From c30decab77c4ebeb34ebd1d73b0f45bb26944c79 Mon Sep 17 00:00:00 2001 From: Kitson Kelly Date: Sun, 15 Sep 2019 22:58:06 +1000 Subject: [PATCH] Fix type directive parsing (#2954) --- js/type_directives.ts | 4 ++-- tests/type_definitions.ts | 4 ++++ tests/type_definitions.ts.out | 2 ++ tests/type_definitions/fizz.d.ts | 4 ++-- tests/type_definitions/fizz.js | 2 +- tests/type_definitions/qat.ts | 1 + 6 files changed, 12 insertions(+), 5 deletions(-) create mode 100644 tests/type_definitions/qat.ts diff --git a/js/type_directives.ts b/js/type_directives.ts index 4817738c79..b457d23940 100644 --- a/js/type_directives.ts +++ b/js/type_directives.ts @@ -39,9 +39,9 @@ const typeDirectiveRegEx = /@deno-types\s*=\s*(["'])((?:(?=(\\?))\3.)*?)\1/gi; * import * as foo from "./foo.js" * export { a, b, c } from "./bar.js" * - * [See Diagram](https://bit.ly/2lK0izL) + * [See Diagram](http://bit.ly/2lOsp0K) */ -const importExportRegEx = /(?:import|export)\s+(?:[\s\S]*?from\s+)?(["'])((?:(?=(\\?))\3.)*?)\1/; +const importExportRegEx = /(?:import|export)(?:\s+|\s+[\s\S]*?from\s+)?(["'])((?:(?=(\\?))\3.)*?)\1/; /** Parses out any Deno type directives that are part of the source code, or * returns `undefined` if there are not any. diff --git a/tests/type_definitions.ts b/tests/type_definitions.ts index 8e85df2b9d..ecf3ae0b20 100644 --- a/tests/type_definitions.ts +++ b/tests/type_definitions.ts @@ -3,4 +3,8 @@ import { foo } from "./type_definitions/foo.js"; // @deno-types="./type_definitions/fizz.d.ts" import "./type_definitions/fizz.js"; +import * as qat from "./type_definitions/qat.ts"; + console.log(foo); +console.log(fizz); +console.log(qat.qat); diff --git a/tests/type_definitions.ts.out b/tests/type_definitions.ts.out index 291e85a7be..b4fa88c509 100644 --- a/tests/type_definitions.ts.out +++ b/tests/type_definitions.ts.out @@ -1 +1,3 @@ [WILDCARD]foo +fizz +qat diff --git a/tests/type_definitions/fizz.d.ts b/tests/type_definitions/fizz.d.ts index 4b087efb7a..34eb41b960 100644 --- a/tests/type_definitions/fizz.d.ts +++ b/tests/type_definitions/fizz.d.ts @@ -1,2 +1,2 @@ -/** An exported value. */ -export const fizz: string; +/** A global value. */ +declare const fizz: string; diff --git a/tests/type_definitions/fizz.js b/tests/type_definitions/fizz.js index 5141a4ddf9..852162c940 100644 --- a/tests/type_definitions/fizz.js +++ b/tests/type_definitions/fizz.js @@ -1 +1 @@ -export const fizz = "fizz"; +globalThis.fizz = "fizz"; diff --git a/tests/type_definitions/qat.ts b/tests/type_definitions/qat.ts new file mode 100644 index 0000000000..6196c9d387 --- /dev/null +++ b/tests/type_definitions/qat.ts @@ -0,0 +1 @@ +export const qat = "qat";