Skip to content

Commit

Permalink
fix: keep extension name in import specifier
Browse files Browse the repository at this point in the history
  • Loading branch information
harttle committed Jun 30, 2020
1 parent b9831ff commit 30cdc2d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
3 changes: 1 addition & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ const defaultOptions = {
return JSON.stringify(moduleIt.path);
}
const isRelative = /^\./.test(name);
const ext = path.extname(name);
const outPath = ext ? (name.replace(new RegExp(ext + '$'), '') + '.php') : (isRelative ? (name + '.php') : name);
const outPath = isRelative ? (name + '.php') : name;
const pathCode = JSON.stringify(outPath);
return isRelative ? `dirname(__FILE__) . '/' . ${pathCode}` : pathCode;
},
Expand Down
3 changes: 3 additions & 0 deletions test/features/helper/foo.bar.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function foo () {

}
7 changes: 6 additions & 1 deletion test/features/import.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ import
```ts
import {Other_Utils as Util} from './helper/some-utils';
import {Some_Utils, func as func1} from './helper/some-utils';
import {foo} from './helper/foo.bar'

import {SomeType, SomeAlias} from './helper/some-types';

foo();

type TplData = {
src?: string,
title?: string
Expand Down Expand Up @@ -40,6 +43,8 @@ import('./Class').then(function () {
require_once(dirname(__FILE__) . '/' . "./helper/some-utils.php");
use \someModule\Other_Utils as Util;
use \someModule\Some_Utils;
require_once(dirname(__FILE__) . '/' . "./helper/foo.bar.php");
\someModule\foo();
$tplData = array();
$tplData["src"] = Some_Utils::makeTcLink("url");
$tplData["title"] = Some_Utils::highlight("title");
Expand All @@ -53,4 +58,4 @@ $c = "isset";
require_once(dirname(__FILE__) . '/' . ("./" . $c) . '.php');
require_once(dirname(__FILE__) . '/' . "./Class.php");
$y = 1;;
```
```

0 comments on commit 30cdc2d

Please sign in to comment.