Use more nodelike paths for import types when possible (#24610)

* Use more nodelike paths for import types when possible

* move functionality from services into compiler, fix with propert file/directory conflict handling

* mark suspect cast
This commit is contained in:
Wesley Wigham 2018-06-05 12:54:36 -07:00 committed by GitHub
parent 735a46f838
commit d9b93903c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 235 additions and 41 deletions

View File

@ -4084,7 +4084,8 @@ namespace ts {
// ambient module, just use declaration/symbol name (fallthrough)
}
else {
return `"${getResolvedExternalModuleName(context!.tracker.moduleResolverHost!, file, getSourceFileOfNode(getOriginalNode(context!.enclosingDeclaration)))}"`;
const contextFile = getSourceFileOfNode(getOriginalNode(context!.enclosingDeclaration))!;
return `"${file.moduleName || moduleSpecifiers.getModuleSpecifier(compilerOptions, contextFile, contextFile.path, file.path, context!.tracker.moduleResolverHost!)}"`;
}
}
const declaration = symbol.declarations[0];

View File

@ -132,10 +132,6 @@ namespace ts {
}
}
export interface GetEffectiveTypeRootsHost {
directoryExists?(directoryName: string): boolean;
getCurrentDirectory?(): string;
}
export function getEffectiveTypeRoots(options: CompilerOptions, host: GetEffectiveTypeRootsHost): string[] | undefined {
if (options.typeRoots) {
return options.typeRoots;

View File

@ -1,10 +1,13 @@
// Used by importFixes to synthesize import module specifiers.
/* @internal */
namespace ts.moduleSpecifiers {
export interface ModuleSpecifierPreferences {
importModuleSpecifierPreference?: "relative" | "non-relative";
}
// Note: fromSourceFile is just for usesJsExtensionOnImports
export function getModuleSpecifier(program: Program, fromSourceFile: SourceFile, fromSourceFileName: string, toFileName: string, host: LanguageServiceHost, preferences: UserPreferences) {
const info = getInfo(program.getCompilerOptions(), fromSourceFile, fromSourceFileName, host);
const compilerOptions = program.getCompilerOptions();
export function getModuleSpecifier(compilerOptions: CompilerOptions, fromSourceFile: SourceFile, fromSourceFileName: string, toFileName: string, host: ModuleSpecifierResolutionHost, preferences: ModuleSpecifierPreferences = {}) {
const info = getInfo(compilerOptions, fromSourceFile, fromSourceFileName, host);
return getGlobalModuleSpecifier(toFileName, info, host, compilerOptions) ||
first(getLocalModuleSpecifiers(toFileName, info, compilerOptions, preferences));
}
@ -14,15 +17,15 @@ namespace ts.moduleSpecifiers {
moduleSymbol: Symbol,
program: Program,
importingSourceFile: SourceFile,
host: LanguageServiceHost,
preferences: UserPreferences,
host: ModuleSpecifierResolutionHost,
preferences: ModuleSpecifierPreferences,
): ReadonlyArray<ReadonlyArray<string>> {
const ambient = tryGetModuleNameFromAmbientModule(moduleSymbol);
if (ambient) return [[ambient]];
const compilerOptions = program.getCompilerOptions();
const info = getInfo(compilerOptions, importingSourceFile, importingSourceFile.fileName, host);
const modulePaths = getAllModulePaths(program, moduleSymbol.valueDeclaration.getSourceFile());
const modulePaths = getAllModulePaths(program, getSourceFileOfNode(moduleSymbol.valueDeclaration));
const global = mapDefined(modulePaths, moduleFileName => getGlobalModuleSpecifier(moduleFileName, info, host, compilerOptions));
return global.length ? global.map(g => [g]) : modulePaths.map(moduleFileName =>
@ -36,10 +39,10 @@ namespace ts.moduleSpecifiers {
readonly sourceDirectory: string;
}
// importingSourceFileName is separate because getEditsForFileRename may need to specify an updated path
function getInfo(compilerOptions: CompilerOptions, importingSourceFile: SourceFile, importingSourceFileName: string, host: LanguageServiceHost): Info {
function getInfo(compilerOptions: CompilerOptions, importingSourceFile: SourceFile, importingSourceFileName: string, host: ModuleSpecifierResolutionHost): Info {
const moduleResolutionKind = getEmitModuleResolutionKind(compilerOptions);
const addJsExtension = usesJsExtensionOnImports(importingSourceFile);
const getCanonicalFileName = hostGetCanonicalFileName(host);
const getCanonicalFileName = createGetCanonicalFileName(host.useCaseSensitiveFileNames ? host.useCaseSensitiveFileNames() : true);
const sourceDirectory = getDirectoryPath(importingSourceFileName);
return { moduleResolutionKind, addJsExtension, getCanonicalFileName, sourceDirectory };
}
@ -47,7 +50,7 @@ namespace ts.moduleSpecifiers {
function getGlobalModuleSpecifier(
moduleFileName: string,
{ addJsExtension, getCanonicalFileName, sourceDirectory }: Info,
host: LanguageServiceHost,
host: ModuleSpecifierResolutionHost,
compilerOptions: CompilerOptions,
) {
return tryGetModuleNameFromTypeRoots(compilerOptions, host, getCanonicalFileName, moduleFileName, addJsExtension)
@ -59,7 +62,7 @@ namespace ts.moduleSpecifiers {
moduleFileName: string,
{ moduleResolutionKind, addJsExtension, getCanonicalFileName, sourceDirectory }: Info,
compilerOptions: CompilerOptions,
preferences: UserPreferences,
preferences: ModuleSpecifierPreferences,
) {
const { baseUrl, paths } = compilerOptions;
@ -210,7 +213,7 @@ namespace ts.moduleSpecifiers {
function tryGetModuleNameAsNodeModule(
options: CompilerOptions,
moduleFileName: string,
host: LanguageServiceHost,
host: ModuleSpecifierResolutionHost,
getCanonicalFileName: (file: string) => string,
sourceDirectory: string,
): string | undefined {
@ -256,7 +259,8 @@ namespace ts.moduleSpecifiers {
const fullModulePathWithoutExtension = removeFileExtension(path);
// If the file is /index, it can be imported by its directory name
if (getCanonicalFileName(fullModulePathWithoutExtension.substring(parts.fileNameIndex)) === "/index") {
// IFF there is not _also_ a file by the same name
if (getCanonicalFileName(fullModulePathWithoutExtension.substring(parts.fileNameIndex)) === "/index" && !tryGetAnyFileFromPath(host, fullModulePathWithoutExtension.substring(0, parts.fileNameIndex))) {
return fullModulePathWithoutExtension.substring(0, parts.fileNameIndex);
}
@ -264,6 +268,17 @@ namespace ts.moduleSpecifiers {
}
}
function tryGetAnyFileFromPath(host: ModuleSpecifierResolutionHost, path: string) {
// We check all js, `node` and `json` extensions in addition to TS, since node module resolution would also choose those over the directory
const extensions = getSupportedExtensions({ allowJs: true }, [{ extension: "node", isMixedContent: false }, { extension: "json", isMixedContent: false, scriptKind: ScriptKind.JSON }]);
for (const e of extensions) {
const fullPath = path + e;
if (host.fileExists!(fullPath)) { // TODO: GH#18217
return fullPath;
}
}
}
interface NodeModulePathParts {
readonly topLevelNodeModulesIndex: number;
readonly topLevelPackageNameIndex: number;

View File

@ -1207,6 +1207,9 @@ namespace ts {
writeFile: writeFileCallback || (
(fileName, data, writeByteOrderMark, onError, sourceFiles) => host.writeFile(fileName, data, writeByteOrderMark, onError, sourceFiles)),
isEmitBlocked,
readFile: f => host.readFile(f),
fileExists: f => host.fileExists(f),
...(host.directoryExists ? { directoryExists: f => host.directoryExists!(f) } : {}),
};
}

View File

@ -44,6 +44,7 @@
"builderState.ts",
"builder.ts",
"resolutionCache.ts",
"moduleSpecifiers.ts",
"watch.ts",
"commandLineParser.ts",
"tsc.ts"

View File

@ -5026,8 +5026,9 @@ namespace ts {
}
/* @internal */
export interface EmitHost extends ScriptReferenceHost {
export interface EmitHost extends ScriptReferenceHost, ModuleSpecifierResolutionHost {
getSourceFiles(): ReadonlyArray<SourceFile>;
getCurrentDirectory(): string;
/* @internal */
isSourceFileFromExternalLibrary(file: SourceFile): boolean;
@ -5289,11 +5290,15 @@ namespace ts {
isAtStartOfLine(): boolean;
}
/* @internal */
export interface ModuleNameResolverHost {
getCanonicalFileName(f: string): string;
getCommonSourceDirectory(): string;
getCurrentDirectory(): string;
export interface GetEffectiveTypeRootsHost {
directoryExists?(directoryName: string): boolean;
getCurrentDirectory?(): string;
}
/** @internal */
export interface ModuleSpecifierResolutionHost extends GetEffectiveTypeRootsHost {
useCaseSensitiveFileNames?(): boolean;
fileExists?(path: string): boolean;
readFile?(path: string): string | undefined;
}
/** @deprecated See comment on SymbolWriter */
@ -5307,7 +5312,7 @@ namespace ts {
reportPrivateInBaseOfClassExpression?(propertyName: string): void;
reportInaccessibleUniqueSymbolError?(): void;
/* @internal */
moduleResolverHost?: ModuleNameResolverHost;
moduleResolverHost?: ModuleSpecifierResolutionHost;
/* @internal */
trackReferencedAmbientModule?(decl: ModuleDeclaration): void;
}

View File

@ -2934,11 +2934,11 @@ namespace ts {
};
}
export function getResolvedExternalModuleName(host: ModuleNameResolverHost, file: SourceFile, referenceFile?: SourceFile): string {
export function getResolvedExternalModuleName(host: EmitHost, file: SourceFile, referenceFile?: SourceFile): string {
return file.moduleName || getExternalModuleNameFromPath(host, file.fileName, referenceFile && referenceFile.fileName);
}
export function getExternalModuleNameFromDeclaration(host: ModuleNameResolverHost, resolver: EmitResolver, declaration: ImportEqualsDeclaration | ImportDeclaration | ExportDeclaration | ModuleDeclaration | ImportTypeNode): string | undefined {
export function getExternalModuleNameFromDeclaration(host: EmitHost, resolver: EmitResolver, declaration: ImportEqualsDeclaration | ImportDeclaration | ExportDeclaration | ModuleDeclaration | ImportTypeNode): string | undefined {
const file = resolver.getExternalModuleFileFromDeclaration(declaration);
if (!file || file.isDeclarationFile) {
return undefined;
@ -2949,7 +2949,7 @@ namespace ts {
/**
* Resolves a local path to a path which is absolute to the base of the emit
*/
export function getExternalModuleNameFromPath(host: ModuleNameResolverHost, fileName: string, referencePath?: string): string {
export function getExternalModuleNameFromPath(host: EmitHost, fileName: string, referencePath?: string): string {
const getCanonicalFileName = (f: string) => host.getCanonicalFileName(f);
const dir = toPath(referencePath ? getDirectoryPath(referencePath) : host.getCommonSourceDirectory(), host.getCurrentDirectory(), getCanonicalFileName);
const filePath = getNormalizedAbsolutePath(fileName, host.getCurrentDirectory());

View File

@ -51,6 +51,7 @@
"../compiler/builderState.ts",
"../compiler/builder.ts",
"../compiler/resolutionCache.ts",
"../compiler/moduleSpecifiers.ts",
"../compiler/watch.ts",
"../compiler/commandLineParser.ts",
@ -115,7 +116,6 @@
"../services/codefixes/inferFromUsage.ts",
"../services/codefixes/fixInvalidImportSyntax.ts",
"../services/codefixes/fixStrictClassInitialization.ts",
"../services/codefixes/moduleSpecifiers.ts",
"../services/codefixes/requireInTs.ts",
"../services/codefixes/useDefaultImport.ts",
"../services/codefixes/fixAddModuleReferTypeMissingTypeof.ts",

View File

@ -47,6 +47,7 @@
"../compiler/builderState.ts",
"../compiler/builder.ts",
"../compiler/resolutionCache.ts",
"../compiler/moduleSpecifiers.ts",
"../compiler/watch.ts",
"../compiler/commandLineParser.ts",
@ -111,7 +112,6 @@
"../services/codefixes/inferFromUsage.ts",
"../services/codefixes/fixInvalidImportSyntax.ts",
"../services/codefixes/fixStrictClassInitialization.ts",
"../services/codefixes/moduleSpecifiers.ts",
"../services/codefixes/requireInTs.ts",
"../services/codefixes/useDefaultImport.ts",
"../services/codefixes/fixAddModuleReferTypeMissingTypeof.ts",

View File

@ -53,6 +53,7 @@
"../compiler/builderState.ts",
"../compiler/builder.ts",
"../compiler/resolutionCache.ts",
"../compiler/moduleSpecifiers.ts",
"../compiler/watch.ts",
"../compiler/commandLineParser.ts",
@ -117,7 +118,6 @@
"../services/codefixes/inferFromUsage.ts",
"../services/codefixes/fixInvalidImportSyntax.ts",
"../services/codefixes/fixStrictClassInitialization.ts",
"../services/codefixes/moduleSpecifiers.ts",
"../services/codefixes/requireInTs.ts",
"../services/codefixes/useDefaultImport.ts",
"../services/codefixes/fixAddModuleReferTypeMissingTypeof.ts",

View File

@ -123,7 +123,7 @@ namespace ts {
// TODO:GH#18217
? getSourceFileToImportFromResolved(resolveModuleName(importLiteral.text, oldImportFromPath, program.getCompilerOptions(), host as ModuleResolutionHost), oldToNew, program)
: getSourceFileToImport(importLiteral, sourceFile, program, host, oldToNew);
return toImport === undefined ? undefined : moduleSpecifiers.getModuleSpecifier(program, sourceFile, newImportFromPath, toImport, host, preferences);
return toImport === undefined ? undefined : moduleSpecifiers.getModuleSpecifier(program.getCompilerOptions(), sourceFile, newImportFromPath, toImport, host, preferences);
});
}
}

View File

@ -44,6 +44,7 @@
"../compiler/builderState.ts",
"../compiler/builder.ts",
"../compiler/resolutionCache.ts",
"../compiler/moduleSpecifiers.ts",
"../compiler/watch.ts",
"../compiler/commandLineParser.ts",
@ -108,7 +109,6 @@
"codefixes/inferFromUsage.ts",
"codefixes/fixInvalidImportSyntax.ts",
"codefixes/fixStrictClassInitialization.ts",
"codefixes/moduleSpecifiers.ts",
"codefixes/requireInTs.ts",
"codefixes/useDefaultImport.ts",
"codefixes/fixAddModuleReferTypeMissingTypeof.ts",

View File

@ -2881,6 +2881,10 @@ declare namespace ts {
omitTrailingSemicolon?: boolean;
noEmitHelpers?: boolean;
}
interface GetEffectiveTypeRootsHost {
directoryExists?(directoryName: string): boolean;
getCurrentDirectory?(): string;
}
/** @deprecated See comment on SymbolWriter */
interface SymbolTracker {
trackSymbol?(symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags): void;
@ -3472,10 +3476,6 @@ declare namespace ts {
function updateSourceFile(sourceFile: SourceFile, newText: string, textChangeRange: TextChangeRange, aggressiveChecks?: boolean): SourceFile;
}
declare namespace ts {
interface GetEffectiveTypeRootsHost {
directoryExists?(directoryName: string): boolean;
getCurrentDirectory?(): string;
}
function getEffectiveTypeRoots(options: CompilerOptions, host: GetEffectiveTypeRootsHost): string[] | undefined;
/**
* @param {string | undefined} containingFile - file that contains type reference directive, can be undefined if containing file is unknown.

View File

@ -2881,6 +2881,10 @@ declare namespace ts {
omitTrailingSemicolon?: boolean;
noEmitHelpers?: boolean;
}
interface GetEffectiveTypeRootsHost {
directoryExists?(directoryName: string): boolean;
getCurrentDirectory?(): string;
}
/** @deprecated See comment on SymbolWriter */
interface SymbolTracker {
trackSymbol?(symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags): void;
@ -3472,10 +3476,6 @@ declare namespace ts {
function updateSourceFile(sourceFile: SourceFile, newText: string, textChangeRange: TextChangeRange, aggressiveChecks?: boolean): SourceFile;
}
declare namespace ts {
interface GetEffectiveTypeRootsHost {
directoryExists?(directoryName: string): boolean;
getCurrentDirectory?(): string;
}
function getEffectiveTypeRoots(options: CompilerOptions, host: GetEffectiveTypeRootsHost): string[] | undefined;
/**
* @param {string | undefined} containingFile - file that contains type reference directive, can be undefined if containing file is unknown.

View File

@ -0,0 +1,38 @@
//// [tests/cases/compiler/declarationEmitCommonJsModuleReferencedType.ts] ////
//// [index.d.ts]
export interface NestedProps {}
//// [index.d.ts]
export interface OtherIndexProps {}
//// [other.d.ts]
export interface OtherProps {}
//// [index.d.ts]
import { OtherProps } from "./other";
import { OtherIndexProps } from "./other/index";
import { NestedProps } from "nested";
export interface SomeProps {}
export function foo(): [SomeProps, OtherProps, OtherIndexProps, NestedProps];
//// [index.d.ts]
export interface RootProps {}
export function bar(): RootProps;
//// [entry.ts]
import { foo } from "foo";
import { bar } from "root";
export const x = foo();
export const y = bar();
//// [entry.js]
"use strict";
exports.__esModule = true;
var foo_1 = require("foo");
var root_1 = require("root");
exports.x = foo_1.foo();
exports.y = root_1.bar();
//// [entry.d.ts]
export declare const x: [import("foo").SomeProps, import("foo/other").OtherProps, import("foo/other/index").OtherIndexProps, import("foo/node_modules/nested").NestedProps];
export declare const y: import("root").RootProps;

View File

@ -0,0 +1,55 @@
=== tests/cases/compiler/r/node_modules/foo/node_modules/nested/index.d.ts ===
export interface NestedProps {}
>NestedProps : Symbol(NestedProps, Decl(index.d.ts, 0, 0))
=== tests/cases/compiler/r/node_modules/foo/other/index.d.ts ===
export interface OtherIndexProps {}
>OtherIndexProps : Symbol(OtherIndexProps, Decl(index.d.ts, 0, 0))
=== tests/cases/compiler/r/node_modules/foo/other.d.ts ===
export interface OtherProps {}
>OtherProps : Symbol(OtherProps, Decl(other.d.ts, 0, 0))
=== tests/cases/compiler/r/node_modules/foo/index.d.ts ===
import { OtherProps } from "./other";
>OtherProps : Symbol(OtherProps, Decl(index.d.ts, 0, 8))
import { OtherIndexProps } from "./other/index";
>OtherIndexProps : Symbol(OtherIndexProps, Decl(index.d.ts, 1, 8))
import { NestedProps } from "nested";
>NestedProps : Symbol(NestedProps, Decl(index.d.ts, 2, 8))
export interface SomeProps {}
>SomeProps : Symbol(SomeProps, Decl(index.d.ts, 2, 37))
export function foo(): [SomeProps, OtherProps, OtherIndexProps, NestedProps];
>foo : Symbol(foo, Decl(index.d.ts, 3, 29))
>SomeProps : Symbol(SomeProps, Decl(index.d.ts, 2, 37))
>OtherProps : Symbol(OtherProps, Decl(index.d.ts, 0, 8))
>OtherIndexProps : Symbol(OtherIndexProps, Decl(index.d.ts, 1, 8))
>NestedProps : Symbol(NestedProps, Decl(index.d.ts, 2, 8))
=== tests/cases/compiler/node_modules/root/index.d.ts ===
export interface RootProps {}
>RootProps : Symbol(RootProps, Decl(index.d.ts, 0, 0))
export function bar(): RootProps;
>bar : Symbol(bar, Decl(index.d.ts, 0, 29))
>RootProps : Symbol(RootProps, Decl(index.d.ts, 0, 0))
=== tests/cases/compiler/r/entry.ts ===
import { foo } from "foo";
>foo : Symbol(foo, Decl(entry.ts, 0, 8))
import { bar } from "root";
>bar : Symbol(bar, Decl(entry.ts, 1, 8))
export const x = foo();
>x : Symbol(x, Decl(entry.ts, 2, 12))
>foo : Symbol(foo, Decl(entry.ts, 0, 8))
export const y = bar();
>y : Symbol(y, Decl(entry.ts, 3, 12))
>bar : Symbol(bar, Decl(entry.ts, 1, 8))

View File

@ -0,0 +1,57 @@
=== tests/cases/compiler/r/node_modules/foo/node_modules/nested/index.d.ts ===
export interface NestedProps {}
>NestedProps : NestedProps
=== tests/cases/compiler/r/node_modules/foo/other/index.d.ts ===
export interface OtherIndexProps {}
>OtherIndexProps : OtherIndexProps
=== tests/cases/compiler/r/node_modules/foo/other.d.ts ===
export interface OtherProps {}
>OtherProps : OtherProps
=== tests/cases/compiler/r/node_modules/foo/index.d.ts ===
import { OtherProps } from "./other";
>OtherProps : any
import { OtherIndexProps } from "./other/index";
>OtherIndexProps : any
import { NestedProps } from "nested";
>NestedProps : any
export interface SomeProps {}
>SomeProps : SomeProps
export function foo(): [SomeProps, OtherProps, OtherIndexProps, NestedProps];
>foo : () => [SomeProps, OtherProps, OtherIndexProps, NestedProps]
>SomeProps : SomeProps
>OtherProps : OtherProps
>OtherIndexProps : OtherIndexProps
>NestedProps : NestedProps
=== tests/cases/compiler/node_modules/root/index.d.ts ===
export interface RootProps {}
>RootProps : RootProps
export function bar(): RootProps;
>bar : () => RootProps
>RootProps : RootProps
=== tests/cases/compiler/r/entry.ts ===
import { foo } from "foo";
>foo : () => [import("tests/cases/compiler/r/node_modules/foo/index").SomeProps, import("tests/cases/compiler/r/node_modules/foo/other").OtherProps, import("tests/cases/compiler/r/node_modules/foo/other/index").OtherIndexProps, import("tests/cases/compiler/r/node_modules/foo/node_modules/nested/index").NestedProps]
import { bar } from "root";
>bar : () => import("tests/cases/compiler/node_modules/root/index").RootProps
export const x = foo();
>x : [import("tests/cases/compiler/r/node_modules/foo/index").SomeProps, import("tests/cases/compiler/r/node_modules/foo/other").OtherProps, import("tests/cases/compiler/r/node_modules/foo/other/index").OtherIndexProps, import("tests/cases/compiler/r/node_modules/foo/node_modules/nested/index").NestedProps]
>foo() : [import("tests/cases/compiler/r/node_modules/foo/index").SomeProps, import("tests/cases/compiler/r/node_modules/foo/other").OtherProps, import("tests/cases/compiler/r/node_modules/foo/other/index").OtherIndexProps, import("tests/cases/compiler/r/node_modules/foo/node_modules/nested/index").NestedProps]
>foo : () => [import("tests/cases/compiler/r/node_modules/foo/index").SomeProps, import("tests/cases/compiler/r/node_modules/foo/other").OtherProps, import("tests/cases/compiler/r/node_modules/foo/other/index").OtherIndexProps, import("tests/cases/compiler/r/node_modules/foo/node_modules/nested/index").NestedProps]
export const y = bar();
>y : import("tests/cases/compiler/node_modules/root/index").RootProps
>bar() : import("tests/cases/compiler/node_modules/root/index").RootProps
>bar : () => import("tests/cases/compiler/node_modules/root/index").RootProps

View File

@ -21,4 +21,4 @@ exports.thing = umd_1.makeThing();
//// [index.d.ts]
export declare const thing: import("./node_modules/umd").Thing;
export declare const thing: import("umd").Thing;

View File

@ -0,0 +1,23 @@
// @declaration: true
// @filename: r/node_modules/foo/node_modules/nested/index.d.ts
export interface NestedProps {}
// @filename: r/node_modules/foo/other/index.d.ts
export interface OtherIndexProps {}
// @filename: r/node_modules/foo/other.d.ts
export interface OtherProps {}
// @filename: r/node_modules/foo/index.d.ts
import { OtherProps } from "./other";
import { OtherIndexProps } from "./other/index";
import { NestedProps } from "nested";
export interface SomeProps {}
export function foo(): [SomeProps, OtherProps, OtherIndexProps, NestedProps];
// @filename: node_modules/root/index.d.ts
export interface RootProps {}
export function bar(): RootProps;
// @filename: r/entry.ts
import { foo } from "foo";
import { bar } from "root";
export const x = foo();
export const y = bar();