2 var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3 if (k2 === undefined) k2 = k;
4 Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5 }) : (function(o, m, k, k2) {
6 if (k2 === undefined) k2 = k;
9 var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10 Object.defineProperty(o, "default", { enumerable: true, value: v });
14 var __importStar = (this && this.__importStar) || function (mod) {
15 if (mod && mod.__esModule) return mod;
17 if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18 __setModuleDefault(result, mod);
21 var __importDefault = (this && this.__importDefault) || function (mod) {
22 return (mod && mod.__esModule) ? mod : { "default": mod };
24 Object.defineProperty(exports, "__esModule", { value: true });
25 exports.getTsconfigPath = exports.getScriptKind = exports.getCanonicalFileName = exports.ensureAbsolutePath = exports.createDefaultCompilerOptionsFromExtra = exports.canonicalDirname = void 0;
26 const path_1 = __importDefault(require("path"));
27 const ts = __importStar(require("typescript"));
29 * Default compiler options for program generation from single root file
31 const DEFAULT_COMPILER_OPTIONS = {
32 allowNonTsExtensions: true,
36 // extendedDiagnostics: true,
38 * Flags required to make no-unused-vars work
41 noUnusedParameters: true,
43 function createDefaultCompilerOptionsFromExtra(extra) {
44 if (extra.debugLevel.has('typescript')) {
45 return Object.assign(Object.assign({}, DEFAULT_COMPILER_OPTIONS), { extendedDiagnostics: true });
47 return DEFAULT_COMPILER_OPTIONS;
49 exports.createDefaultCompilerOptionsFromExtra = createDefaultCompilerOptionsFromExtra;
50 // typescript doesn't provide a ts.sys implementation for browser environments
51 const useCaseSensitiveFileNames = ts.sys !== undefined ? ts.sys.useCaseSensitiveFileNames : true;
52 const correctPathCasing = useCaseSensitiveFileNames
53 ? (filePath) => filePath
54 : (filePath) => filePath.toLowerCase();
55 function getCanonicalFileName(filePath) {
56 let normalized = path_1.default.normalize(filePath);
57 if (normalized.endsWith(path_1.default.sep)) {
58 normalized = normalized.substr(0, normalized.length - 1);
60 return correctPathCasing(normalized);
62 exports.getCanonicalFileName = getCanonicalFileName;
63 function ensureAbsolutePath(p, extra) {
64 return path_1.default.isAbsolute(p)
66 : path_1.default.join(extra.tsconfigRootDir || process.cwd(), p);
68 exports.ensureAbsolutePath = ensureAbsolutePath;
69 function getTsconfigPath(tsconfigPath, extra) {
70 return getCanonicalFileName(ensureAbsolutePath(tsconfigPath, extra));
72 exports.getTsconfigPath = getTsconfigPath;
73 function canonicalDirname(p) {
74 return path_1.default.dirname(p);
76 exports.canonicalDirname = canonicalDirname;
77 function getScriptKind(extra, filePath = extra.filePath) {
78 const extension = path_1.default.extname(filePath).toLowerCase();
79 // note - we respect the user's extension when it is known we could override it and force it to match their
80 // jsx setting, but that could create weird situations where we throw parse errors when TSC doesn't
83 return ts.ScriptKind.TS;
85 return ts.ScriptKind.TSX;
87 return ts.ScriptKind.JS;
89 return ts.ScriptKind.JSX;
91 return ts.ScriptKind.JSON;
93 // unknown extension, force typescript to ignore the file extension, and respect the user's setting
94 return extra.jsx ? ts.ScriptKind.TSX : ts.ScriptKind.TS;
97 exports.getScriptKind = getScriptKind;
98 //# sourceMappingURL=shared.js.map