Skip to content
Closed
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Prev Previous commit
prototype - 4
  • Loading branch information
ShuiRuTian committed Jul 1, 2020
commit 2afe126afcab6627a9c441dd4a8ebc1e4d1ab9fd
6 changes: 3 additions & 3 deletions NoNameSpace/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ async function fileCB(filePath: string) {
let newFileContent = "";
let removeNamespaceFlag = false;
for await (const line of rl) {
// const namespaceRE = RegExp("^(declare )?namespace ts.*?\\{$");
const namespaceTsRE = RegExp("^(declare )?namespace ts \\{$");
const namespaceRE = RegExp("^(declare )?namespace .*?\\{$");
// const namespaceTsRE = RegExp("^(declare )?namespace ts \\{$");
const namespaceEndRE = RegExp("^\\}$");
// const noNamespaceTsdotRE = /(?<!namespace)(\W)ts\./g;
const tsdotRE = /(\W)ts\./g;
if (namespaceTsRE.test(line)) {
if (namespaceRE.test(line)) {
//skip, not output
removeNamespaceFlag = true;
}
Expand Down
5 changes: 3 additions & 2 deletions NoNameSpace/vscodeFixAutoImports.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ var triggerEvent = new KeyboardEvent("keydown", {
// ATTENTION!!!!!!
// this event could not be triggered normally
// you need to copy one global event and rename it to arrowDownEvent
// document.addEventListener('keydown',function(e){console.log(e)})
// arrowDownEvent = temp1
//
// function l(e){console.log(e)};document.addEventListener('keydown',l);
// arrowDownEvent = temp1;document.removeEventListener('keydown',l);
var arrowDownEventFALSE = new KeyboardEvent("keyDown", {
altKey: false,
bubbles: true,
Expand Down
57 changes: 57 additions & 0 deletions scripts/generateEnumType.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import readline from "readline";
import fs from "fs";
import path from "path";

const enumConstConvert = [
"SyntaxKind",
"NodeFlags",
"ModifierFlags",
"TransformFlags",
"EmitFlags",
"SymbolFlags",
"TypeFlags",
"ObjectFlags"
];

// wish this is /src/compiler/types.ts
// const inputFilePath = path.resolve(__dirname, "../src/compiler/types.ts");
const inputFilePath = process.argv[2].replace(/\\/g, "/");

function writeFile(fileName: string, contents: string) {
fs.writeFile(path.join(path.dirname(inputFilePath), fileName), contents, { encoding: "utf-8" }, err => {
if (err) throw err;
});
}

function isThisLineConstEnumRegenerated(line: string) {
return enumConstConvert.some(e => RegExp(`export const enum ${e}`).test(line));
}

async function generateFile(filePath: string) {
const fileStream = fs.createReadStream(filePath);

const rl = readline.createInterface({
input: fileStream,
// crlfDelay: Infinity
});
let newFileContent = "";
let acceptThisLineFlag = false;
for await (const line of rl) {
if (isThisLineConstEnumRegenerated(line)) {
acceptThisLineFlag = true;
const newLine = line.replace("export", "").replace("const", "");
newFileContent += newLine;
newFileContent += "\r\n";
} else if (acceptThisLineFlag) {
newFileContent += line;
newFileContent += "\r\n";
}
if (line.includes("}")) {
acceptThisLineFlag = false;
}
}
newFileContent += `export const EnumType = {${enumConstConvert.join(",")}}`;
writeFile("types.generated.ts", newFileContent);
}

generateFile(inputFilePath);
14 changes: 11 additions & 3 deletions src/compat/deprecations.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace ts {

// The following are deprecations for the public API. Deprecated exports are removed from the compiler itself
// and compatible implementations are added here, along with an appropriate deprecation warning using
// the `@deprecated` JSDoc tag as well as the `Debug.deprecate` API.
Expand All @@ -9,6 +9,14 @@ namespace ts {
// * "warn" - Warning deprecations are indicated with the `@deprecated` JSDoc Tag and a diagnostic message (assuming a compatible host)
// * "error" - Error deprecations are indicated with the `@deprecated` JSDoc tag and will throw a `TypeError` when invoked.

import { Debug, DeprecationOptions } from "../compiler/debug";
import { SyntaxKind, Token, Identifier, Node, GeneratedIdentifierFlags, Decorator, Modifier, ParameterDeclaration, TypeNode, IndexSignatureDeclaration, ThisTypeNode, TypePredicateNode, PseudoBigInt, StringLiteral, NoSubstitutionTemplateLiteral, NumericLiteral, PrimaryExpression, BooleanLiteral, TypeParameterDeclaration, PropertyName, QuestionToken, MethodSignature, NodeArray, TypeOperatorNode, Expression, TemplateLiteral, TaggedTemplateExpression, BinaryExpression, BinaryOperator, BinaryOperatorToken, ColonToken, ConditionalExpression, AsteriskToken, YieldExpression, HeritageClause, ClassElement, ClassExpression, PropertySignature, ExpressionWithTypeArguments, ConciseBody, EqualsGreaterThanToken, ArrowFunction, BindingName, ExclamationToken, VariableDeclaration, NamedImportBindings, ImportClause, NamedExportBindings, ExportDeclaration, EntityName, JSDocTypeExpression, JSDocParameterTag, PostfixUnaryExpression, PrefixUnaryExpression, TypeAssertion } from "../compiler/types";
import { setTextRangePosEnd, setParent } from "../compiler/utilities";
import { parseBaseNodeFactory } from "../compiler/parser";
import { factory } from "../compiler/factory/nodeFactory";
import { setTextRange } from "../compiler/factory/utilitiesPublic";
import { isNodeKind } from "../compiler/utilitiesPublic";

// DEPRECATION: Node factory top-level exports
// DEPRECATION PLAN:
// - soft: 4.0
Expand All @@ -17,7 +25,7 @@ namespace ts {
// #region Node factory top-level exports

// NOTE: These exports are deprecated in favor of using a `NodeFactory` instance and exist here purely for backwards compatibility reasons.
const factoryDeprecation: DeprecationOptions = { since: "4.0", warnAfter: "4.1", message: "Use the appropriate method on 'ts.factory' or the 'factory' supplied by your transformation context instead." };
const factoryDeprecation: DeprecationOptions = { since: "4.0", warnAfter: "4.1", message: "Use the appropriate method on 'factory' or the 'factory' supplied by your transformation context instead." };

/** @deprecated Use `factory.createNodeArray` or the factory supplied by your transformation context instead. */
export const createNodeArray = Debug.deprecate(factory.createNodeArray, factoryDeprecation);
Expand Down Expand Up @@ -1321,4 +1329,4 @@ namespace ts {
});

// #endregion Renamed node Tests
}
21 changes: 16 additions & 5 deletions src/compiler/binder.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@

/* @internal */
namespace ts {

import { __String, Symbol, FlowLabel, ModuleDeclaration, Node, SyntaxKind, EnumDeclaration, ModifierFlags, ExportDeclaration, Identifier, ExportSpecifier, FlowNode, SourceFile, CompilerOptions, ScriptTarget, JSDocTypedefTag, JSDocCallbackTag, JSDocEnumTag, NodeFlags, SymbolFlags, UnderscoreEscapedMap, FlowFlags, DiagnosticMessage, DiagnosticWithLocation, Declaration, ExportAssignment, InternalSymbolName, StringLiteral, PropertyAccessExpression, BinaryExpression, AssignmentDeclarationKind, JSDocFunctionType, ParameterDeclaration, SymbolTable, DiagnosticRelatedInformation, FunctionLikeDeclaration, FunctionExpression, ArrowFunction, MethodDeclaration, NodeArray, WhileStatement, DoStatement, ForStatement, ForInOrOfStatement, IfStatement, ReturnStatement, ThrowStatement, BreakOrContinueStatement, TryStatement, SwitchStatement, CaseBlock, CaseClause, ExpressionStatement, LabeledStatement, PrefixUnaryExpression, PostfixUnaryExpression, DeleteExpression, ConditionalExpression, VariableDeclaration, AccessExpression, CallExpression, NonNullExpression, Block, Expression, ParenthesizedExpression, TypeOfExpression, FlowReduceLabel, ArrayBindingElement, Statement, ArrayLiteralExpression, SpreadElement, ObjectLiteralExpression, ElementAccessExpression, JSDocClassTag, OptionalChain, NonNullChain, PropertyAccessChain, ElementAccessChain, CallChain, PropertyDeclaration, PatternAmbientModule, SignatureDeclaration, JSDocSignature, JsxAttributes, JsxAttribute, PrivateIdentifier, CatchClause, FunctionDeclaration, NumericLiteral, TokenFlags, WithStatement, TextRange, DiagnosticCategory, BindableStaticPropertyAssignmentExpression, BindablePropertyAssignmentExpression, TypeParameterDeclaration, BindingElement, PropertySignature, TypeLiteralNode, MappedTypeNode, JSDocTypeLiteral, BindableObjectDefinePropertyCall, ClassLikeDeclaration, NamespaceExportDeclaration, ImportClause, ModuleBlock, JSDocParameterTag, JSDocPropertyLikeTag, LiteralLikeElementAccessExpression, DynamicNamedDeclaration, EntityNameExpression, BindableStaticAccessExpression, BindableStaticNameExpression, BindableAccessExpression, ConditionalTypeNode, JSDoc } from "./types";
import { setParent, setParentRecursive, isEnumConst, hasSyntacticModifier, createDiagnosticForNodeInSourceFile, getSourceFileOfNode, getEmitScriptTarget, createUnderscoreEscapedMap, objectAllocator, getStrictOptionValue, createSymbolTable, setValueDeclaration, isAmbientModule, getTextOfIdentifierOrLiteral, isGlobalScopeAugmentation, isStringOrNumericLiteralLike, isSignedNumericLiteral, isWellKnownSymbolSyntactically, getPropertyNameForKnownSymbolName, getContainingClass, getSymbolNameForPrivateIdentifier, isPropertyNameLiteral, getEscapedTextOfIdentifierOrLiteral, getAssignmentDeclarationKind, isJSDocConstructSignature, declarationNameToString, hasDynamicName, nodeIsMissing, addRelatedInfo, isJSDocTypeAlias, isInJSFile, Mutable, getImmediatelyInvokedFunctionExpression, nodeIsPresent, skipParentheses, isLogicalOrCoalescingAssignmentOperator, isDottedName, unusedLabelIsError, isAssignmentOperator, isAssignmentTarget, getHostSignatureFromJSDoc, isPushOrUnshiftIdentifier, isObjectLiteralOrClassExpressionMethod, isModuleAugmentationExternal, hasZeroOrOneAsteriskCharacter, tryParsePattern, getErrorSpanForNode, createFileDiagnostic, isExternalOrCommonJsModule, getJSDocHost, findAncestor, getEnclosingBlockScopeContainer, isPropertyAccessEntityNameExpression, getAssignmentDeclarationPropertyAccessKind, isIdentifierName, isInTopLevelContext, getSpanOfTokenAtPosition, getTokenPosOfNode, isPrologueDirective, getSourceTextOfNodeFromSourceFile, isSpecialPropertyDeclaration, isModuleExportsAccessExpression, isObjectLiteralMethod, isJsonSourceFile, removeFileExtension, exportAssignmentIsAlias, getRightMostAssignedExpression, isEmptyObjectLiteral, getThisContainer, isBindableStaticAccessExpression, isPrototypeAccess, isFunctionSymbol, isBindableStaticNameExpression, getAssignedExpandoInitializer, isBindableObjectDefinePropertyCall, getExpandoInitializer, getElementOrPropertyAccessName, getNameOrArgument, isRequireCall, isBlockOrCatchScoped, isParameterDeclaration, isAsyncFunction, unreachableCodeIsError, sliceAfter, isExportsIdentifier, isAssignmentExpression } from "./utilities";
import { getNodeId } from "./checker";
import { forEachChild, isExternalModule } from "./parser";
import { Debug } from "./debug";
import { isBlock, isModuleBlock, isSourceFile, isPrivateIdentifier, isExportSpecifier, isTypeAliasDeclaration, isPropertyAccessExpression, isNonNullExpression, isParenthesizedExpression, isElementAccessExpression, isTypeOfExpression, isBinaryExpression, isPrefixUnaryExpression, isOmittedExpression, isIdentifier, isExportDeclaration, isExportAssignment, isJSDocEnumTag, isVariableStatement, isNamespaceExport, isClassExpression, isCallExpression, isVariableDeclaration, isConditionalTypeNode, isJSDocTemplateTag, isFunctionDeclaration, isEnumDeclaration } from "./factory/nodeTests";
import { nodeHasName, getNameOfDeclaration, escapeLeadingUnderscores, idText, isNamedDeclaration, unescapeLeadingUnderscores, getCombinedModifierFlags, isOptionalChain, isStringLiteralLike, isExpressionOfOptionalChainRoot, isNullishCoalesce, isOutermostOptionalChain, isBindingPattern, isForInOrOfStatement, isOptionalChainRoot, isFunctionLike, isLeftHandSideExpression, isDeclarationStatement, hasJSDocNodes, isExpression, isFunctionLikeDeclaration, symbolName, isParameterPropertyDeclaration, isStatementButNotDeclaration, getCombinedNodeFlags, isStatement } from "./utilitiesPublic";
import { perfLogger } from "./perfLogger";
import { appendIfUnique, forEach, contains, concatenate, tryCast, Pattern, append, cast, some, find, getRangesWhere, length } from "./core";
import { tokenToString } from "./scanner";
import { performance } from "perf_hooks";
export const enum ModuleInstanceState {
NonInstantiated = 0,
Instantiated = 1,
Expand Down Expand Up @@ -217,7 +228,7 @@ namespace ts {

let symbolCount = 0;

let Symbol: new (flags: SymbolFlags, name: __String) => Symbol;
let SymbolConstructor: new (flags: SymbolFlags, name: __String) => Symbol;
let classifiableNames: UnderscoreEscapedMap<true>;

const unreachableFlow: FlowNode = { flags: FlowFlags.Unreachable };
Expand All @@ -240,7 +251,7 @@ namespace ts {
classifiableNames = createUnderscoreEscapedMap<true>();
symbolCount = 0;

Symbol = objectAllocator.getSymbolConstructor();
SymbolConstructor = objectAllocator.getSymbolConstructor();

// Attach debugging information if necessary
Debug.attachFlowNodeDebugInfo(unreachableFlow);
Expand Down Expand Up @@ -289,7 +300,7 @@ namespace ts {

function createSymbol(flags: SymbolFlags, name: __String): Symbol {
symbolCount++;
return new Symbol(flags, name);
return new SymbolConstructor(flags, name);
}

function addDeclarationToSymbol(symbol: Symbol, node: Declaration, symbolFlags: SymbolFlags) {
Expand Down Expand Up @@ -3423,4 +3434,4 @@ namespace ts {
}
return container.symbol && container.symbol.exports && container.symbol.exports.get(name);
}
}

19 changes: 17 additions & 2 deletions src/compiler/builder.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
/*@internal*/
namespace ts {

import { CompilerOptions, DiagnosticCategory, DiagnosticMessageChain, Path, Diagnostic, SourceFile, Program, DiagnosticRelatedInformation, CancellationToken, EmitResult, CompilerOptionsValue, CommandLineOption, CompilerHost, ProjectReference, WriteFileCallback, CustomTransformers, SourceMapEmitResult } from "./types";
import { ReusableBuilderState, BuilderState } from "./builderState";
import { ReadonlyCollection, MapLike } from "./corePublic";
import { forEachKey, outFile, compilerOptionsAffectSemanticDiagnostics, forEachEntry, compilerOptionsAffectEmit, skipTypeChecking, getEmitDeclarations } from "./utilities";
import { GetCanonicalFileName, neverArray, forEach, tryAddToSet, concatenate, arrayFrom, compareStringsCaseSensitive, hasProperty, createGetCanonicalFileName, notImplemented, maybeBind, addRange, arrayToMap, map, noop, returnUndefined } from "./core";
import { Debug } from "./debug";
import { getDirectoryPath, getNormalizedAbsolutePath, toPath, ensurePathIsNonModuleName, getRelativePathFromDirectory } from "./path";
import { getTsBuildInfoEmitOutputFilePath } from "./emitter";
import { AffectedFileResult, BuilderProgramHost, BuilderProgram, SemanticDiagnosticsBuilderProgram, EmitAndSemanticDiagnosticsBuilderProgram } from "./builderPublic";
import { filterSemanticDiagnotics, createProgram, emitSkippedWithNoDiagnostics, handleNoEmitOptions } from "./program";
import { getOptionsNameMap, convertToOptionsWithAbsolutePaths } from "./commandLineParser";
import { isArray, isString } from "util";
import { generateDjb2Hash } from "./sys";
import { ReadBuildProgramHost } from "./watchPublic";

export interface ReusableDiagnostic extends ReusableDiagnosticRelatedInformation {
/** May store more in future. For now, this will simply be `true` to indicate when a diagnostic is an unused-identifier diagnostic. */
reportsUnnecessary?: {};
Expand Down Expand Up @@ -1237,4 +1252,4 @@ namespace ts {
return Debug.checkDefined(state.program);
}
}
}

6 changes: 4 additions & 2 deletions src/compiler/builderPublic.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace ts {
import { SourceFile, Program, WriteFileCallback, CompilerOptions, CancellationToken, Diagnostic, DiagnosticWithLocation, CustomTransformers, EmitResult, CompilerHost, ProjectReference } from "./types";
import { ReusableBuilderProgramState, createBuilderProgram, BuilderProgramKind, getBuilderCreationParameters, createRedirectedBuilderProgram } from "./builder";

export type AffectedFileResult<T> = { result: T; affected: SourceFile | Program; } | undefined;

export interface BuilderProgramHost {
Expand Down Expand Up @@ -161,4 +163,4 @@ namespace ts {
const { newProgram, configFileParsingDiagnostics: newConfigFileParsingDiagnostics } = getBuilderCreationParameters(newProgramOrRootNames, hostOrOptions, oldProgramOrHost, configFileParsingDiagnosticsOrOldProgram, configFileParsingDiagnostics, projectReferences);
return createRedirectedBuilderProgram({ program: newProgram, compilerOptions: newProgram.getCompilerOptions() }, newConfigFileParsingDiagnostics);
}
}

13 changes: 11 additions & 2 deletions src/compiler/builderState.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
/*@internal*/
namespace ts {

import { Program, SourceFile, CancellationToken, CustomTransformers, Path, TypeChecker, StringLiteralLike, ModuleKind, Extension, ExportedModulesFromDeclarationEmit, ModuleDeclaration } from "./types";
import { EmitOutput, OutputFile } from "./builderStatePublic";
import { getSourceFileOfNode, outFile, isModuleWithStringLiteralName, isGlobalScopeAugmentation } from "./utilities";
import { GetCanonicalFileName, neverArray, arrayFrom, mapDefinedIterator, some } from "./core";
import { toPath, getDirectoryPath, fileExtensionIs, getAnyExtensionFromPath } from "./path";
import { isStringLiteral } from "./factory/nodeTests";
import { Debug } from "./debug";
import { isExternalModule } from "./parser";

export function getFileEmitOutput(program: Program, sourceFile: SourceFile, emitOnlyDtsFiles: boolean,
cancellationToken?: CancellationToken, customTransformers?: CustomTransformers, forceDtsEmit?: boolean): EmitOutput {
const outputFiles: OutputFile[] = [];
Expand Down Expand Up @@ -552,4 +561,4 @@ namespace ts {
return arrayFrom(mapDefinedIterator(seenFileNamesMap.values(), value => value));
}
}
}

5 changes: 3 additions & 2 deletions src/compiler/builderStatePublic.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
namespace ts {
import { Diagnostic, ExportedModulesFromDeclarationEmit } from "./types";

export interface EmitOutput {
outputFiles: OutputFile[];
emitSkipped: boolean;
Expand All @@ -11,4 +12,4 @@ namespace ts {
writeByteOrderMark: boolean;
text: string;
}
}

6 changes: 4 additions & 2 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* @internal */
namespace ts {

const ambientModuleSymbolRegex = /^".+"$/;
const anon = "(anonymous)" as __String & string;

Expand Down Expand Up @@ -20112,6 +20112,7 @@ namespace ts {
((<TransientSymbol>prop).checkFlags & CheckFlags.Discriminant) === CheckFlags.Discriminant &&
!maybeTypeOfKind(getTypeOfSymbol(prop), TypeFlags.Instantiable);
}

return !!(<TransientSymbol>prop).isDiscriminantProperty;
}
}
Expand Down Expand Up @@ -30615,6 +30616,7 @@ namespace ts {

// Private class fields transformation relies on WeakMaps.
if (isPrivateIdentifier(node.name) && languageVersion < ScriptTarget.ESNext) {

for (let lexicalScope = getEnclosingBlockScopeContainer(node); !!lexicalScope; lexicalScope = getEnclosingBlockScopeContainer(lexicalScope)) {
getNodeLinks(lexicalScope).flags |= NodeCheckFlags.ContainsClassWithPrivateIdentifiers;
}
Expand Down Expand Up @@ -39224,4 +39226,4 @@ namespace ts {
return !!(s.flags & SignatureFlags.HasLiteralTypes);
}

}

Loading