Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
factor out isJsxOrTsxExtension
  • Loading branch information
Andy Hanson committed Jun 6, 2016
commit a918730df0919357fbe8accd88a873991ef11fa6
4 changes: 4 additions & 0 deletions src/compiler/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,10 @@ namespace ts {
return fileExtensionIs(path, extension) ? path.substring(0, path.length - extension.length) : undefined;
}

export function isJsxOrTsxExtension(ext: string): boolean {
return ext === ".jsx" || ext === ".tsx";
}

export interface ObjectAllocator {
getNodeConstructor(): new (kind: SyntaxKind, pos?: number, end?: number) => Node;
getSourceFileConstructor(): new (kind: SyntaxKind, pos?: number, end?: number) => SourceFile;
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ namespace ts {
return forEach(extensions, tryLoad);
Copy link
Contributor

@mhegazy mhegazy May 31, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider this pattern, split the function into a loadModuleFromFile and loadModuleFromFileWorker. the worker is never called directly except from loaModulefronFile. and loadModuleFromFile becomes:

    function loadModuleFromFile(candidate: string, extensions: string[], failedLookupLocation: string[], onlyRecordFailures: boolean, state: ModuleResolutionState): string {
        return loadModuleFromFileWorker(candidate, extensions, failedLookupLocation, onlyRecordFailures, state) ||
            hasJavaScriptFileExtension(candidate) ? loadModuleFromFileWorker(removeFileExtension(candidate), extensionsm failedLookupLocation, onlyRecordFailures, state) : undefined;
    }

you would want to make it more explicit off course and add some tracing.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could it be function worker(candidate) in a closure or would that be bad for perf?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i do not know :). @vladima thoughts?


function tryLoad(ext: string): string {
if (state.skipTsx && (ext === ".jsx" || ext === ".tsx")) {
if (state.skipTsx && isJsxOrTsxExtension(ext)) {
return undefined;
}
const fileName = fileExtensionIs(candidate, ext) ? candidate : candidate + ext;
Expand Down