Skip to content

Commit

Permalink
fix: type directives import (#2910)
Browse files Browse the repository at this point in the history
  • Loading branch information
bartlomieju authored and ry committed Sep 11, 2019
1 parent df5b6cd commit a4e1d7d
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
8 changes: 4 additions & 4 deletions js/type_directives.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.

interface DirectiveInfo {
path: string;
start: number;
Expand Down Expand Up @@ -33,15 +32,16 @@ export function getMappedModuleName(
*/
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:
*
* import "./foo.js"
* import * as foo from "./foo.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
* returns `undefined` if there are not any.
Expand Down
2 changes: 2 additions & 0 deletions tests/type_definitions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// @deno-types="./type_definitions/foo.d.ts"
import { foo } from "./type_definitions/foo.js";
// @deno-types="./type_definitions/fizz.d.ts"
import "./type_definitions/fizz.js";

console.log(foo);
2 changes: 2 additions & 0 deletions tests/type_definitions/fizz.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/** An exported value. */
export const fizz: string;
1 change: 1 addition & 0 deletions tests/type_definitions/fizz.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const fizz = "fizz";

0 comments on commit a4e1d7d

Please sign in to comment.