Fix type directive parsing (#2954)

This commit is contained in:
Kitson Kelly 2019-09-15 22:58:06 +10:00 committed by Ryan Dahl
parent 686b86edb1
commit c30decab77
6 changed files with 12 additions and 5 deletions

View file

@ -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.

View file

@ -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);

View file

@ -1 +1,3 @@
[WILDCARD]foo
fizz
qat

View file

@ -1,2 +1,2 @@
/** An exported value. */
export const fizz: string;
/** A global value. */
declare const fizz: string;

View file

@ -1 +1 @@
export const fizz = "fizz";
globalThis.fizz = "fizz";

View file

@ -0,0 +1 @@
export const qat = "qat";