1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-28 16:20:57 -05:00

fix: type directives import (#2910)

This commit is contained in:
Bartek Iwańczuk 2019-09-11 12:47:34 +02:00 committed by Ryan Dahl
parent df5b6cdd7f
commit a4e1d7d2e7
4 changed files with 9 additions and 4 deletions

View file

@ -1,5 +1,4 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
interface DirectiveInfo { interface DirectiveInfo {
path: string; path: string;
start: number; start: number;
@ -33,15 +32,16 @@ export function getMappedModuleName(
*/ */
const typeDirectiveRegEx = /@deno-types\s*=\s*(["'])((?:(?=(\\?))\3.)*?)\1/gi; const typeDirectiveRegEx = /@deno-types\s*=\s*(["'])((?:(?=(\\?))\3.)*?)\1/gi;
/** Matches `import` or `export from` statements and parses out the value of the /** Matches `import`, `import from` or `export from` statements and parses out the value of the
* module specifier in the second capture group: * module specifier in the second capture group:
* *
* import "./foo.js"
* import * as foo from "./foo.js" * import * as foo from "./foo.js"
* export { a, b, c } from "./bar.js" * export { a, b, c } from "./bar.js"
* *
* [See Diagram](http://bit.ly/2GSkJlF) * [See Diagram](https://bit.ly/2lK0izL)
*/ */
const importExportRegEx = /(?:import|export)\s+[\s\S]*?from\s+(["'])((?:(?=(\\?))\3.)*?)\1/; const importExportRegEx = /(?:import|export)\s+(?:[\s\S]*?from\s+)?(["'])((?:(?=(\\?))\3.)*?)\1/;
/** Parses out any Deno type directives that are part of the source code, or /** Parses out any Deno type directives that are part of the source code, or
* returns `undefined` if there are not any. * returns `undefined` if there are not any.

View file

@ -1,4 +1,6 @@
// @deno-types="./type_definitions/foo.d.ts" // @deno-types="./type_definitions/foo.d.ts"
import { foo } from "./type_definitions/foo.js"; import { foo } from "./type_definitions/foo.js";
// @deno-types="./type_definitions/fizz.d.ts"
import "./type_definitions/fizz.js";
console.log(foo); console.log(foo);

2
tests/type_definitions/fizz.d.ts vendored Normal file
View file

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

View file

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