Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.8k
docs(website): load typescript libs in playground#4765
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
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Uh oh!
There was an error while loading.Please reload this page.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,55 @@ | ||
import { analyze } from '@typescript-eslint/scope-manager/dist/analyze'; | ||
import { visitorKeys } from '@typescript-eslint/visitor-keys/dist/visitor-keys'; | ||
import { astConverter } from '@typescript-eslint/typescript-estree/dist/ast-converter'; | ||
import { extra } from './config.js'; | ||
import { CompilerHost } from './CompilerHost'; | ||
import { createProgram } from 'typescript'; | ||
export function createASTProgram(code, isJsx, compilerOptions, libs) { | ||
const fileName = isJsx ? '/demo.tsx' : '/demo.ts'; | ||
const compilerHost = new CompilerHost(libs, isJsx); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. ideally we would like to use watch compiler host, but that can come latter | ||
compilerHost.files[fileName] = code; | ||
const program = createProgram( | ||
Object.keys(compilerHost.files), | ||
compilerOptions, | ||
compilerHost, | ||
); | ||
const ast = program.getSourceFile(fileName); | ||
return { | ||
ast, | ||
program, | ||
}; | ||
} | ||
export function parseForESLint(code, eslintOptions, compilerOptions, libs) { | ||
const isJsx = eslintOptions.ecmaFeatures?.jsx ?? false; | ||
const { ast: tsAst, program } = createASTProgram( | ||
code, | ||
isJsx, | ||
compilerOptions, | ||
libs, | ||
); | ||
const { estree: ast, astMaps } = astConverter( | ||
tsAst, | ||
{ ...extra, code, jsx: isJsx }, | ||
true, | ||
); | ||
const services = { | ||
hasFullTypeInformation: true, | ||
program, | ||
esTreeNodeToTSNodeMap: astMaps.esTreeNodeToTSNodeMap, | ||
tsNodeToESTreeNodeMap: astMaps.tsNodeToESTreeNodeMap, | ||
}; | ||
const scopeManager = analyze(ast, { | ||
ecmaVersion: | ||
eslintOptions.ecmaVersion === 'latest' ? 1e8 :eslintOptions.ecmaVersion, | ||
globalReturn:eslintOptions.ecmaFeatures?.globalReturn ?? false, | ||
sourceType:eslintOptions.sourceType ?? 'script', | ||
}); | ||
return { | ||