Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

chore: add some tests and refactor tsconfig path resolution#412

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
JamesHenry merged 1 commit intotypescript-eslint:masterfromdsgkirkby:parser-services-performance-remnants
Apr 7, 2019
Merged
Show file tree
Hide file tree
Changes fromall commits
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
21 changes: 9 additions & 12 deletionspackages/typescript-estree/src/tsconfig-parser.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -50,6 +50,12 @@ function diagnosticReporter(diagnostic: ts.Diagnostic): void {

const noopFileWatcher = { close: () => {} };

function getTsconfigPath(tsconfigPath: string, extra: Extra): string {
return path.isAbsolute(tsconfigPath)
? tsconfigPath
: path.join(extra.tsconfigRootDir || process.cwd(), tsconfigPath);
}

/**
* Calculate project environments using options provided by consumer and paths from config
* @param code The code being linted
Expand All@@ -64,7 +70,6 @@ export function calculateProjectParserOptions(
extra: Extra,
): ts.Program[] {
const results = [];
const tsconfigRootDir = extra.tsconfigRootDir;

// preserve reference to code and file being linted
currentLintOperationState.code = code;
Expand All@@ -77,11 +82,8 @@ export function calculateProjectParserOptions(
watchCallback(filePath, ts.FileWatcherEventKind.Changed);
}

for (let tsconfigPath of extra.projects) {
// if absolute paths aren't provided, make relative to tsconfigRootDir
if (!path.isAbsolute(tsconfigPath)) {
tsconfigPath = path.join(tsconfigRootDir, tsconfigPath);
}
for (let rawTsconfigPath of extra.projects) {
const tsconfigPath = getTsconfigPath(rawTsconfigPath, extra);

const existingWatch = knownWatchProgramMap.get(tsconfigPath);

Expand DownExpand Up@@ -193,12 +195,7 @@ export function createProgram(code: string, filePath: string, extra: Extra) {
return undefined;
}

let tsconfigPath = extra.projects[0];

// if absolute paths aren't provided, make relative to tsconfigRootDir
if (!path.isAbsolute(tsconfigPath)) {
tsconfigPath = path.join(extra.tsconfigRootDir, tsconfigPath);
}
const tsconfigPath = getTsconfigPath(extra.projects[0], extra);

const commandLine = ts.getParsedCommandLineOfConfigFile(
tsconfigPath,
Expand Down
47 changes: 47 additions & 0 deletionspackages/typescript-estree/tests/lib/semanticInfo.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -48,6 +48,21 @@ describe('semanticInfo', () => {
);
});

it(`should cache the created ts.program`, () => {
const filename = testFiles[0];
const code = readFileSync(filename, 'utf8');
const options = createOptions(filename);
const optionsProjectString = {
...options,
project: './tsconfig.json',
};
expect(
parseAndGenerateServices(code, optionsProjectString).services.program,
).toBe(
parseAndGenerateServices(code, optionsProjectString).services.program,
);
});

it(`should handle "project": "./tsconfig.json" and "project": ["./tsconfig.json"] the same`, () => {
const filename = testFiles[0];
const code = readFileSync(filename, 'utf8');
Expand All@@ -65,6 +80,38 @@ describe('semanticInfo', () => {
);
});

it(`should resolve absolute and relative tsconfig paths the same`, () => {
const filename = testFiles[0];
const code = readFileSync(filename, 'utf8');
const options = createOptions(filename);
const optionsAbsolutePath = {
...options,
project: `${__dirname}/../fixtures/semanticInfo/tsconfig.json`,
};
const optionsRelativePath = {
...options,
project: `./tsconfig.json`,
};
const absolutePathResult = parseAndGenerateServices(
code,
optionsAbsolutePath,
);
const relativePathResult = parseAndGenerateServices(
code,
optionsRelativePath,
);
if (absolutePathResult.services.program === undefined) {
throw new Error('Unable to create ts.program for absolute tsconfig');
} else if (relativePathResult.services.program === undefined) {
throw new Error('Unable to create ts.program for relative tsconfig');
}
expect(
absolutePathResult.services.program.getResolvedProjectReferences(),
).toEqual(
relativePathResult.services.program.getResolvedProjectReferences(),
);
});

// case-specific tests
it('isolated-file tests', () => {
const fileName = resolve(FIXTURES_DIR, 'isolated-file.src.ts');
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp