package js_parser
Import Path
github.com/evanw/esbuild/internal/js_parser (on go.dev )
Dependency Relation
imports 15 packages , and imported by 4 packages
Package-Level Type Names (total 38, in which 2 are exported)
/* sort exporteds by: alphabet | popularity */
type Options (struct)
This is used as part of an incremental build cache key. Some of these values
can potentially change between builds if they are derived from nearby
"package.json" or "tsconfig.json" files that were changed since the last
build.
Fields (total 18, none are exported )
/* 18 unexporteds ... */ /* 18 unexporteds: */
defines *config .ProcessedDefines
This pointer will always be different for each build but the contents
shouldn't ever behave different semantically. We ignore this field for the
equality comparison.
injectedFiles []config .InjectedFile
jsx config .JSXOptions
optionsThatSupportStructuralEquality optionsThatSupportStructuralEquality
This is an embedded struct. Always access these directly instead of off
the name "optionsThatSupportStructuralEquality". This is only grouped like
this to make the equality comparison easier and safer (and hopefully faster).
optionsThatSupportStructuralEquality .asciiOnly bool
optionsThatSupportStructuralEquality .ignoreDCEAnnotations bool
optionsThatSupportStructuralEquality .keepNames bool
optionsThatSupportStructuralEquality .mangleSyntax bool
optionsThatSupportStructuralEquality .minifyIdentifiers bool
optionsThatSupportStructuralEquality .mode config .Mode
optionsThatSupportStructuralEquality .omitRuntimeForTests bool
optionsThatSupportStructuralEquality .outputFormat config .Format
optionsThatSupportStructuralEquality .platform config .Platform
optionsThatSupportStructuralEquality .preserveUnusedImportsTS bool
optionsThatSupportStructuralEquality .suppressWarningsAboutWeirdCode bool
optionsThatSupportStructuralEquality .ts config .TSOptions
Byte-sized values go here (gathered together here to keep this object compact)
optionsThatSupportStructuralEquality .unsupportedJSFeatures compat .JSFeature
optionsThatSupportStructuralEquality .useDefineForClassFields bool
Methods (only one, which is exported )
(*T) Equal (b *Options ) bool
As Outputs Of (at least one exported )
func OptionsFromConfig (options *config .Options ) Options
As Inputs Of (at least 5, in which 4 are exported )
func LazyExportAST (log logger .Log , source logger .Source , options Options , expr js_ast .Expr , apiCall string ) js_ast .AST
func Parse (log logger .Log , source logger .Source , options Options ) (result js_ast .AST , ok bool )
func (*Options).Equal (b *Options ) bool
func github.com/evanw/esbuild/internal/cache.(*JSCache ).Parse (log logger .Log , source logger .Source , options Options ) (js_ast .AST , bool )
/* at least one unexported ... */ /* at least one unexported: */
func newParser (log logger .Log , source logger .Source , lexer js_lexer .Lexer , options *Options ) *parser
/* 36 unexporteds ... */ /* 36 unexporteds: */ type parser (struct)
This parser does two passes:
1. Parse the source into an AST, create the scope tree, and declare symbols.
2. Visit each node in the AST, bind identifiers to declared symbols, do
constant folding, substitute compile-time variable definitions, and
lower certain syntactic constructs as appropriate given the language
target.
So many things have been put in so few passes because we want to minimize
the number of full-tree passes to improve performance. However, we need
to have at least two separate passes to handle variable hoisting. See the
comment about scopesInOrder below for more information.
Fields (total 76, none are exported )
/* 76 unexporteds ... */ /* 76 unexporteds: */
afterArrowBodyLoc logger .Loc
ArrowFunction is a special case in the grammar. Although it appears to be
a PrimaryExpression, it's actually an AssigmentExpression. This means if
a AssigmentExpression ends up producing an ArrowFunction then nothing can
come after it other than the comma operator, since the comma operator is
the only thing above AssignmentExpression under the Expression rule:
AssignmentExpression:
ArrowFunction
ConditionalExpression
LeftHandSideExpression = AssignmentExpression
LeftHandSideExpression AssignmentOperator AssignmentExpression
Expression:
AssignmentExpression
Expression , AssignmentExpression
allocatedNames []string
allowIn bool
allowPrivateIdentifiers bool
awaitTarget js_ast .E
This helps recognize the "await import()" pattern. When this is present,
warnings about non-string import paths will be omitted inside try blocks.
callTarget js_ast .E
These properties are for the visit pass, which runs after the parse pass.
The visit pass binds identifiers to declared symbols, does constant
folding, substitutes compile-time variable definitions, and lowers certain
syntactic constructs as appropriate.
cjsDotTarget js_ast .E
This helps recognize the "require.someProperty" pattern. If this pattern is
present and the output format is CommonJS, we avoid generating a warning
about an unbundled use of "require".
currentScope *js_ast .Scope
declaredSymbols []js_ast .DeclaredSymbol
deleteTarget js_ast .E
duplicateCaseChecker duplicateCaseChecker
emittedNamespaceVars map[js_ast .Ref ]bool
enclosingClassKeyword logger .Range
enclosingNamespaceArgRef *js_ast .Ref
This is the reference to the generated function argument for the namespace,
which is different than the reference to the namespace itself:
namespace ns {
}
The code above is transformed into something like this:
var ns1;
(function(ns2) {
})(ns1 || (ns1 = {}));
This variable is "ns2" not "ns1". It is only used during the second
"visit" pass.
es6ExportKeyword logger .Range
es6ImportKeyword logger .Range
These are for handling ES6 imports and exports
exportStarImportRecords []uint32
exportsRef js_ast .Ref
findSymbolHelper func(loc logger .Loc , name string ) js_ast .Ref
fnOnlyDataVisit fnOnlyDataVisit
fnOrArrowDataParse fnOrArrowDataParse
fnOrArrowDataVisit fnOrArrowDataVisit
forbidSuffixAfterAsLoc logger .Loc
hasESModuleSyntax bool
hasImportMeta bool
hasTopLevelReturn bool
hoistedRefForSloppyModeBlockFn map[js_ast .Ref ]js_ast .Ref
For strict mode handling
importItemsForNamespace map[js_ast .Ref ]map[string ]js_ast .LocRef
importMetaRef js_ast .Ref
importRecords []ast .ImportRecord
Imports (both ES6 and CommonJS) are tracked at the top level
importRecordsForCurrentPart []uint32
injectedDefineSymbols []js_ast .Ref
isControlFlowDead bool
isExportedInsideNamespace map[js_ast .Ref ]js_ast .Ref
isImportItem map[js_ast .Ref ]bool
knownEnumValues map[js_ast .Ref ]map[string ]float64
lackOfDefineWarnings map[string ]bool
latestArrowArgLoc logger .Loc
latestReturnHadSemicolon bool
legacyOctalLiterals map[js_ast .E ]logger .Range
lexer js_lexer .Lexer
localTypeNames map[string ]bool
log logger .Log
loopBody js_ast .S
moduleRef js_ast .Ref
moduleScope *js_ast .Scope
namedExports map[string ]js_ast .NamedExport
namedImports map[js_ast .Ref ]js_ast .NamedImport
nonBMPIdentifiers map[string ]bool
options Options
privateGetters map[js_ast .Ref ]js_ast .Ref
privateSetters map[js_ast .Ref ]js_ast .Ref
promiseRef js_ast .Ref
relocatedTopLevelVars []js_ast .LocRef
When bundling, hoisted top-level local variables declared with "var" in
nested scopes are moved up to be declared in the top-level scope instead.
The old "var" statements are turned into regular assignments instead. This
makes it easier to quickly scan the top-level statements for "var" locals
with the guarantee that all will be found.
requireRef js_ast .Ref
resolveCallTarget js_ast .E
This helps recognize calls to "require.resolve()" which may become
ERequireResolve expressions.
runtimeImports map[string ]js_ast .Ref
scopesForCurrentPart []*js_ast .Scope
scopesInOrder []scopeOrder
The parser does two passes and we need to pass the scope tree information
from the first pass to the second pass. That's done by tracking the calls
to pushScopeForParsePass() and popScope() during the first pass in
scopesInOrder.
Then, when the second pass calls pushScopeForVisitPass() and popScope(),
we consume entries from scopesInOrder and make sure they are in the same
order. This way the second pass can efficiently use the same scope tree
as the first pass without having to attach the scope tree to the AST.
We need to split this into two passes because the pass that declares the
symbols must be separate from the pass that binds identifiers to declared
symbols to handle declaring a hoisted "var" symbol in a nested scope and
binding a name to it in a parent or sibling scope.
shouldFoldNumericConstants bool
These are for TypeScript
source logger .Source
symbolForDefineHelper func(int ) js_ast .Ref
symbolUses map[js_ast .Ref ]js_ast .SymbolUse
symbols []js_ast .Symbol
tempRefCount int
tempRefsToDeclare []tempRef
Temporary variables used for lowering
thenCatchChain thenCatchChain
This helps recognize the "import().catch()" pattern. We also try to avoid
warning about this just like the "try { await import() }" pattern.
topLevelAwaitKeyword logger .Range
topLevelSymbolToParts map[js_ast .Ref ][]uint32
tsUseCounts []uint32
typeofRequire js_ast .E
typeofRequireEqualsFn js_ast .E
typeofRequireEqualsFnTarget js_ast .E
typeofTarget js_ast .E
These are for recognizing "typeof require == 'function' && require". This
is a workaround for code that browserify generates that looks like this:
(function e(t, n, r) {
function s(o2, u) {
if (!n[o2]) {
if (!t[o2]) {
var a = typeof require == "function" && require;
if (!u && a)
return a(o2, true);
if (i)
return i(o2, true);
throw new Error("Cannot find module '" + o2 + "'");
}
var f = n[o2] = {exports: {}};
t[o2][0].call(f.exports, function(e2) {
var n2 = t[o2][1][e2];
return s(n2 ? n2 : e2);
}, f, f.exports, e, t, n, r);
}
return n[o2].exports;
}
var i = typeof require == "function" && require;
for (var o = 0; o < r.length; o++)
s(r[o]);
return s;
});
It's checking to see if the environment it's running in has a "require"
function before calling it. However, esbuild's bundling environment has a
bundle-time require function because it's a bundler. So in this case
"typeof require == 'function'" is true and the "&&" expression just
becomes a single "require" identifier, which will then crash at run time.
The workaround is to explicitly pattern-match for the exact expression
"typeof require == 'function' && require" and replace it with "false" if
we're targeting the browser.
Note that we can't just leave "typeof require == 'function'" alone because
there is other code in the wild that legitimately does need it to become
"true" when bundling. Specifically, the package "@dagrejs/graphlib" has
code that looks like this:
if (typeof require === "function") {
try {
lodash = {
clone: require("lodash/clone"),
constant: require("lodash/constant"),
each: require("lodash/each"),
// ... more calls to require() here ...
};
} catch (e) {
// continue regardless of error
}
}
That library will crash later on during startup if that branch isn't
taken because "typeof require === 'function'" is false at run time.
weakMapRef js_ast .Ref
For lowering private methods
weakSetRef js_ast .Ref
Methods (total 179, none are exported )
/* 179 unexporteds ... */ /* 179 unexporteds: */
(*T) addImportRecord (kind ast .ImportKind , loc logger .Loc , text string ) uint32
(*T) appendPart (parts []js_ast .Part , stmts []js_ast .Stmt ) []js_ast .Part
(*T) bindingCanBeRemovedIfUnused (binding js_ast .Binding ) bool
(*T) callRuntime (loc logger .Loc , name string , args []js_ast .Expr ) js_ast .Expr
(*T) canFollowTypeArgumentsInExpression () bool
This function is taken from the official TypeScript compiler source code:
https://github.com/microsoft/TypeScript/blob/master/src/compiler/parser.ts
(*T) canMergeSymbols (scope *js_ast .Scope , existing js_ast .SymbolKind , new js_ast .SymbolKind ) mergeResult
(*T) captureArguments () js_ast .Ref
(*T) captureKeyForObjectRest (originalKey js_ast .Expr ) (finalKey js_ast .Expr , capturedKey func() js_ast .Expr )
Save a copy of the key for the call to "__rest" later on. Certain
expressions can be converted to keys more efficiently than others.
(*T) captureThis () js_ast .Ref
(*T) captureValueWithPossibleSideEffects (loc logger .Loc , count int , value js_ast .Expr ) (func() js_ast .Expr , func(js_ast .Expr ) js_ast .Expr )
This is a helper function to use when you need to capture a value that may
have side effects so you can use it multiple times. It guarantees that the
side effects take place exactly once.
Example usage:
// "value" => "value + value"
// "value()" => "(_a = value(), _a + _a)"
valueFunc, wrapFunc := p.captureValueWithPossibleSideEffects(loc, 2, value)
return wrapFunc(js_ast.Expr{Loc: loc, Data: &js_ast.EBinary{
Op: js_ast.BinOpAdd,
Left: valueFunc(),
Right: valueFunc(),
}})
This returns a function for generating references instead of a raw reference
because AST nodes are supposed to be unique in memory, not aliases of other
AST nodes. That way you can mutate one during lowering without having to
worry about messing up other nodes.
(*T) checkForLegacyOctalLiteral (e js_ast .E )
(*T) checkForNonBMPCodePoint (loc logger .Loc , name string )
(*T) classCanBeRemovedIfUnused (class js_ast .Class ) bool
(*T) computeCharacterFrequency () *js_ast .CharFreq
Compute a character frequency histogram for everything that's not a bound
symbol. This is used to modify how minified names are generated for slightly
better gzip compression. Even though it's a very small win, we still do it
because it's simple to do and very cheap to compute.
(*T) convertBindingToExpr (binding js_ast .Binding , wrapIdentifier func(logger .Loc , js_ast .Ref ) js_ast .Expr ) js_ast .Expr
(*T) convertExprToBinding (expr js_ast .Expr , invalidLog []logger .Loc ) (js_ast .Binding , []logger .Loc )
Note: do not write to "p.log" in this function. Any errors due to conversion
from expression to binding should be written to "invalidLog" instead. That
way we can potentially keep this as an expression if it turns out it's not
needed as a binding after all.
(*T) convertExprToBindingAndInitializer (expr js_ast .Expr , invalidLog []logger .Loc , isSpread bool ) (js_ast .Binding , *js_ast .Expr , []logger .Loc )
(*T) declareBinding (kind js_ast .SymbolKind , binding js_ast .Binding , opts parseStmtOpts )
(*T) declareCommonJSSymbol (kind js_ast .SymbolKind , name string ) js_ast .Ref
(*T) declareSymbol (kind js_ast .SymbolKind , loc logger .Loc , name string ) js_ast .Ref
(*T) discardScopesUpTo (scopeIndex int )
Undo all scopes pushed and popped after this scope index. This assumes that
the scope stack is at the same level now as it was at the given scope index.
(*T) exprCanBeRemovedIfUnused (expr js_ast .Expr ) bool
(*T) extractPrivateIndex (target js_ast .Expr ) (js_ast .Expr , logger .Loc , *js_ast .EPrivateIdentifier )
(*T) findLabelSymbol (loc logger .Loc , name string ) (ref js_ast .Ref , isLoop bool , ok bool )
(*T) findSymbol (loc logger .Loc , name string ) findSymbolResult
(*T) forbidInitializers (decls []js_ast .Decl , loopType string , isVar bool )
(*T) forbidLexicalDecl (loc logger .Loc )
(*T) generateClosureForTypeScriptNamespaceOrEnum (stmts []js_ast .Stmt , stmtLoc logger .Loc , isExport bool , nameLoc logger .Loc , nameRef js_ast .Ref , argRef js_ast .Ref , stmtsInsideClosure []js_ast .Stmt ) []js_ast .Stmt
(*T) generateImportStmt (path string , imports []string , sourceIndex uint32 , parts []js_ast .Part , symbols map[string ]js_ast .Ref ) []js_ast .Part
(*T) generateTempRef (declare generateTempRefArg , optionalName string ) js_ast .Ref
(*T) handleIdentifier (loc logger .Loc , e *js_ast .EIdentifier , opts identifierOpts ) js_ast .Expr
(*T) hoistSymbols (scope *js_ast .Scope )
(*T) ignoreUsage (ref js_ast .Ref )
(*T) isAnonymousNamedExpr (expr js_ast .Expr ) bool
(*T) isDotDefineMatch (expr js_ast .Expr , parts []string ) bool
(*T) isPrivateUnsupported (private *js_ast .EPrivateIdentifier ) bool
(*T) isStrictMode () bool
(*T) isStrictModeOutputFormat () bool
(*T) isValidAssignmentTarget (expr js_ast .Expr ) bool
(*T) jsxStringsToMemberExpression (loc logger .Loc , parts []string ) js_ast .Expr
(*T) keepExprSymbolName (value js_ast .Expr , name string ) js_ast .Expr
(*T) keepStmtSymbolName (loc logger .Loc , ref js_ast .Ref , name string ) js_ast .Stmt
(*T) keyNameForError (key js_ast .Expr ) string
(*T) loadNameFromRef (ref js_ast .Ref ) string
This is the inverse of storeNameInRef() above
(*T) logArrowArgErrors (errors *deferredArrowArgErrors )
(*T) logExprErrors (errors *deferredErrors )
(*T) lowerAssignmentOperator (value js_ast .Expr , callback func(js_ast .Expr , js_ast .Expr ) js_ast .Expr ) js_ast .Expr
(*T) lowerClass (stmt js_ast .Stmt , expr js_ast .Expr , shadowRef js_ast .Ref ) ([]js_ast .Stmt , js_ast .Expr )
Lower class fields for environments that don't support them. This either
takes a statement or an expression.
(*T) lowerExponentiationAssignmentOperator (loc logger .Loc , e *js_ast .EBinary ) js_ast .Expr
(*T) lowerFunction (isAsync *bool , args *[]js_ast .Arg , bodyLoc logger .Loc , bodyStmts *[]js_ast .Stmt , preferExpr *bool , hasRestArg *bool , isArrow bool )
(*T) lowerLogicalAssignmentOperator (loc logger .Loc , e *js_ast .EBinary , op js_ast .OpCode ) js_ast .Expr
(*T) lowerNullishCoalescing (loc logger .Loc , left js_ast .Expr , right js_ast .Expr ) js_ast .Expr
(*T) lowerNullishCoalescingAssignmentOperator (loc logger .Loc , e *js_ast .EBinary ) js_ast .Expr
(*T) lowerObjectRestHelper (rootExpr js_ast .Expr , rootInit js_ast .Expr , assign func(js_ast .Expr , js_ast .Expr ), declare generateTempRefArg ) bool
(*T) lowerObjectRestInAssign (rootExpr js_ast .Expr , rootInit js_ast .Expr ) (js_ast .Expr , bool )
(*T) lowerObjectRestInCatchBinding (catch *js_ast .Catch )
(*T) lowerObjectRestInDecls (decls []js_ast .Decl ) []js_ast .Decl
(*T) lowerObjectRestInForLoopInit (init js_ast .Stmt , body *js_ast .Stmt )
(*T) lowerObjectRestToDecls (rootExpr js_ast .Expr , rootInit js_ast .Expr , decls []js_ast .Decl ) ([]js_ast .Decl , bool )
(*T) lowerObjectSpread (loc logger .Loc , e *js_ast .EObject ) js_ast .Expr
Lower object spread for environments that don't support them. Non-spread
properties are grouped into object literals and then passed to __assign()
like this (__assign() is an alias for Object.assign()):
"{a, b, ...c, d, e}" => "__assign(__assign(__assign({a, b}, c), {d, e})"
If the object literal starts with a spread, then we pass an empty object
literal to __assign() to make sure we clone the object:
"{...a, b}" => "__assign(__assign({}, a), {b})"
It's not immediately obvious why we don't compile everything to a single
call to __assign(). After all, Object.assign() can take any number of
arguments. The reason is to preserve the order of side effects. Consider
this code:
let a = {get x() { b = {y: 2}; return 1 }}
let b = {}
let c = {...a, ...b}
Converting the above code to "let c = __assign({}, a, b)" means "c" becomes
"{x: 1}" which is incorrect. Converting the above code instead to
"let c = __assign(__assign({}, a), b)" means "c" becomes "{x: 1, y: 2}"
which is correct.
(*T) lowerOptionalChain (expr js_ast .Expr , in exprIn , childOut exprOut ) (js_ast .Expr , exprOut )
(*T) lowerPrivateGet (target js_ast .Expr , loc logger .Loc , private *js_ast .EPrivateIdentifier ) js_ast .Expr
(*T) lowerPrivateSet (target js_ast .Expr , loc logger .Loc , private *js_ast .EPrivateIdentifier , value js_ast .Expr ) js_ast .Expr
(*T) lowerPrivateSetBinOp (target js_ast .Expr , loc logger .Loc , private *js_ast .EPrivateIdentifier , op js_ast .OpCode , value js_ast .Expr ) js_ast .Expr
(*T) lowerPrivateSetUnOp (target js_ast .Expr , loc logger .Loc , private *js_ast .EPrivateIdentifier , op js_ast .OpCode , isSuffix bool ) js_ast .Expr
(*T) lowerSuperPropertyAccess (loc logger .Loc , key js_ast .Expr ) js_ast .Expr
(*T) makePromiseRef () js_ast .Ref
(*T) mangleIf (stmts []js_ast .Stmt , loc logger .Loc , s *js_ast .SIf ) []js_ast .Stmt
(*T) mangleIfExpr (loc logger .Loc , e *js_ast .EIf ) js_ast .Expr
(*T) mangleStmts (stmts []js_ast .Stmt , kind stmtsKind ) []js_ast .Stmt
(*T) mangleTemplate (loc logger .Loc , e *js_ast .ETemplate ) js_ast .Expr
"`a${'b'}c`" => "`abc`"
(*T) markExportedBindingInsideNamespace (nsRef js_ast .Ref , binding js_ast .Binding )
(*T) markExportedDeclsInsideNamespace (nsRef js_ast .Ref , decls []js_ast .Decl )
(*T) markExprAsParenthesized (value js_ast .Expr )
(*T) markLoweredSyntaxFeature (feature compat .JSFeature , r logger .Range , loweredFeature compat .JSFeature )
Mark the feature if "loweredFeature" is unsupported. This is used when one
feature is implemented in terms of another feature.
(*T) markStrictModeFeature (feature strictModeFeature , r logger .Range , detail string )
(*T) markSyntaxFeature (feature compat .JSFeature , r logger .Range ) (didGenerateError bool )
(*T) maybeKeepExprSymbolName (value js_ast .Expr , name string , wasAnonymousNamedExpr bool ) js_ast .Expr
(*T) maybeLowerSuperPropertyAccessInsideCall (call *js_ast .ECall )
(*T) maybeRelocateVarsToTopLevel (decls []js_ast .Decl , mode relocateVarsMode ) (js_ast .Stmt , bool )
If we are currently in a hoisted child of the module scope, relocate these
declarations to the top level and return an equivalent assignment statement.
Make sure to check that the declaration kind is "var" before calling this.
And make sure to check that the returned statement is not the zero value.
This is done to make it easier to traverse top-level declarations in the linker
during bundling. Now it is sufficient to just scan the top-level statements
instead of having to traverse recursively into the statement tree.
(*T) maybeRewritePropertyAccess (loc logger .Loc , assignTarget js_ast .AssignTarget , isDeleteTarget bool , optionalChain js_ast .OptionalChain , target js_ast .Expr , name string , nameLoc logger .Loc , isCallTarget bool ) (js_ast .Expr , bool )
EDot nodes represent a property access. This function may return an
expression to replace the property access with. It assumes that the
target of the EDot expression has already been visited.
(*T) maybeTransposeIfExprChain (expr js_ast .Expr , visit func(js_ast .Expr ) js_ast .Expr ) js_ast .Expr
(*T) mergeSymbols (old js_ast .Ref , new js_ast .Ref )
This is similar to "js_ast.MergeSymbols" but it works with this parser's
one-level symbol map instead of the linker's two-level symbol map. It also
doesn't handle cycles since they shouldn't come up due to the way this
function is used.
(*T) newSymbol (kind js_ast .SymbolKind , name string ) js_ast .Ref
(*T) parseAndDeclareDecls (kind js_ast .SymbolKind , opts parseStmtOpts ) []js_ast .Decl
(*T) parseArrowBody (args []js_ast .Arg , data fnOrArrowDataParse ) *js_ast .EArrow
(*T) parseAsyncPrefixExpr (asyncRange logger .Range , level js_ast .L ) js_ast .Expr
This parses an expression. This assumes we've already parsed the "async"
keyword and are currently looking at the following token.
(*T) parseBinding () js_ast .Binding
(*T) parseCallArgs () []js_ast .Expr
(*T) parseClass (classKeyword logger .Range , name *js_ast .LocRef , classOpts parseClassOpts ) js_ast .Class
By the time we call this, the identifier and type parameters have already
been parsed. We need to start parsing from the "extends" clause.
(*T) parseClassStmt (loc logger .Loc , opts parseStmtOpts ) js_ast .Stmt
(*T) parseExportClause () ([]js_ast .ClauseItem , bool )
(*T) parseExpr (level js_ast .L ) js_ast .Expr
(*T) parseExprCommon (level js_ast .L , errors *deferredErrors , flags exprFlag ) js_ast .Expr
(*T) parseExprOrBindings (level js_ast .L , errors *deferredErrors ) js_ast .Expr
(*T) parseExprOrLetStmt (opts parseStmtOpts ) (js_ast .Expr , js_ast .Stmt , []js_ast .Decl )
(*T) parseExprWithFlags (level js_ast .L , flags exprFlag ) js_ast .Expr
(*T) parseFn (name *js_ast .LocRef , data fnOrArrowDataParse ) (fn js_ast .Fn , hadBody bool )
(*T) parseFnBody (data fnOrArrowDataParse ) js_ast .FnBody
(*T) parseFnExpr (loc logger .Loc , isAsync bool , asyncRange logger .Range ) js_ast .Expr
(*T) parseFnStmt (loc logger .Loc , opts parseStmtOpts , isAsync bool , asyncRange logger .Range ) js_ast .Stmt
This assumes the "function" token has already been parsed
(*T) parseImportClause () ([]js_ast .ClauseItem , bool )
(*T) parseImportExpr (loc logger .Loc , level js_ast .L ) js_ast .Expr
Note: The caller has already parsed the "import" keyword
(*T) parseJSXElement (loc logger .Loc ) js_ast .Expr
(*T) parseJSXTag () (logger .Range , string , *js_ast .Expr )
(*T) parseLabelName () *js_ast .LocRef
(*T) parseParenExpr (loc logger .Loc , opts parenExprOpts ) js_ast .Expr
This assumes that the open parenthesis has already been parsed by the caller
(*T) parsePath () (logger .Loc , string )
(*T) parsePrefix (level js_ast .L , errors *deferredErrors , flags exprFlag ) js_ast .Expr
(*T) parseProperty (kind js_ast .PropertyKind , opts propertyOpts , errors *deferredErrors ) (js_ast .Property , bool )
(*T) parsePropertyBinding () js_ast .PropertyBinding
(*T) parseStmt (opts parseStmtOpts ) js_ast .Stmt
(*T) parseStmtsUpTo (end js_lexer .T , opts parseStmtOpts ) []js_ast .Stmt
(*T) parseStringLiteral () js_ast .Expr
This assumes the caller has already checked for TStringLiteral or TNoSubstitutionTemplateLiteral
(*T) parseSuffix (left js_ast .Expr , level js_ast .L , errors *deferredErrors , flags exprFlag ) js_ast .Expr
(*T) parseTemplateParts (includeRaw bool ) (parts []js_ast .TemplatePart , legacyOctalLoc logger .Loc )
(*T) parseTypeScriptDecorators () []js_ast .Expr
(*T) parseTypeScriptEnumStmt (loc logger .Loc , opts parseStmtOpts ) js_ast .Stmt
(*T) parseTypeScriptImportEqualsStmt (loc logger .Loc , opts parseStmtOpts , defaultNameLoc logger .Loc , defaultName string ) js_ast .Stmt
This assumes the caller has already parsed the "import" token
(*T) parseTypeScriptNamespaceStmt (loc logger .Loc , opts parseStmtOpts ) js_ast .Stmt
(*T) parseYieldExpr (loc logger .Loc ) js_ast .Expr
(*T) popAndDiscardScope (scopeIndex int )
(*T) popAndFlattenScope (scopeIndex int )
(*T) popScope ()
(*T) prepareForVisitPass ()
(*T) pushScopeForParsePass (kind js_ast .ScopeKind , loc logger .Loc ) int
(*T) pushScopeForVisitPass (kind js_ast .ScopeKind , loc logger .Loc )
(*T) recordDeclaredSymbol (ref js_ast .Ref )
(*T) recordExport (loc logger .Loc , alias string , ref js_ast .Ref )
(*T) recordExportedBinding (binding js_ast .Binding )
(*T) recordUsage (ref js_ast .Ref )
(*T) requireInitializers (decls []js_ast .Decl )
(*T) scanForImportsAndExports (stmts []js_ast .Stmt ) (result scanForImportsAndExportsResult )
(*T) selectLocalKind (kind js_ast .LocalKind ) js_ast .LocalKind
(*T) shouldLowerSuperPropertyAccess (expr js_ast .Expr ) bool
(*T) simplifyBooleanExpr (expr js_ast .Expr ) js_ast .Expr
Simplify syntax when we know it's used inside a boolean context
(*T) simplifyUnusedExpr (expr js_ast .Expr ) js_ast .Expr
This will return a nil expression if the expression can be totally removed
(*T) skipTypeScriptBinding ()
(*T) skipTypeScriptFnArgs ()
(*T) skipTypeScriptInterfaceStmt (opts parseStmtOpts )
(*T) skipTypeScriptObjectType ()
(*T) skipTypeScriptParenOrFnType ()
This is a spot where the TypeScript grammar is highly ambiguous. Here are
some cases that are valid:
let x = (y: any): (() => {}) => { };
let x = (y: any): () => {} => { };
let x = (y: any): (y) => {} => { };
let x = (y: any): (y[]) => {};
let x = (y: any): (a | b) => {};
Here are some cases that aren't valid:
let x = (y: any): (y) => {};
let x = (y: any): (y) => {return 0};
let x = (y: any): asserts y is (y) => {};
(*T) skipTypeScriptReturnType ()
(*T) skipTypeScriptType (level js_ast .L )
(*T) skipTypeScriptTypeArguments (isInsideJSXElement bool ) bool
(*T) skipTypeScriptTypeParameters ()
This is the type parameter declarations that go with other symbol
declarations (class, function, type, etc.)
(*T) skipTypeScriptTypePrefix ()
(*T) skipTypeScriptTypeStmt (opts parseStmtOpts )
(*T) skipTypeScriptTypeSuffix (level js_ast .L )
(*T) stmtsCanBeRemovedIfUnused (stmts []js_ast .Stmt ) bool
(*T) storeNameInRef (name string ) js_ast .Ref
The name is temporarily stored in the ref until the scope traversal pass
happens, at which point a symbol will be generated and the ref will point
to the symbol instead.
The scope traversal pass will reconstruct the name using one of two methods.
In the common case, the name is a slice of the file itself. In that case we
can just store the slice and not need to allocate any extra memory. In the
rare case, the name is an externally-allocated string. In that case we store
an index to the string and use that index during the scope traversal pass.
(*T) substituteSingleUseSymbolInExpr (expr js_ast .Expr , ref js_ast .Ref , replacement js_ast .Expr , replacementCanBeRemoved bool ) (js_ast .Expr , substituteStatus )
(*T) substituteSingleUseSymbolInStmt (stmt js_ast .Stmt , ref js_ast .Ref , replacement js_ast .Expr ) bool
(*T) toAST (source logger .Source , parts []js_ast .Part , hashbang string , directive string ) js_ast .AST
(*T) trySkipTypeScriptArrowArgsWithBacktracking () bool
(*T) trySkipTypeScriptArrowReturnTypeWithBacktracking () bool
(*T) trySkipTypeScriptTypeArgumentsWithBacktracking () bool
(*T) trySkipTypeScriptTypeParametersThenOpenParenWithBacktracking () bool
(*T) validateJSX (span js_ast .Span , name string ) []string
(*T) valueForDefine (loc logger .Loc , assignTarget js_ast .AssignTarget , isDeleteTarget bool , defineFunc config .DefineFunc ) js_ast .Expr
(*T) valueForThis (loc logger .Loc ) (js_ast .Expr , bool )
(*T) visitAndAppendStmt (stmts []js_ast .Stmt , stmt js_ast .Stmt ) []js_ast .Stmt
(*T) visitArgs (args []js_ast .Arg , opts visitArgsOpts )
(*T) visitBinding (binding js_ast .Binding , opts bindingOpts )
(*T) visitClass (nameScopeLoc logger .Loc , class *js_ast .Class ) js_ast .Ref
(*T) visitExpr (expr js_ast .Expr ) js_ast .Expr
(*T) visitExprInOut (expr js_ast .Expr , in exprIn ) (js_ast .Expr , exprOut )
This function takes "exprIn" as input from the caller and produces "exprOut"
for the caller to pass along extra data. This is mostly for optional chaining.
(*T) visitFn (fn *js_ast .Fn , scopeLoc logger .Loc )
(*T) visitForLoopInit (stmt js_ast .Stmt , isInOrOf bool ) js_ast .Stmt
(*T) visitLoopBody (stmt js_ast .Stmt ) js_ast .Stmt
(*T) visitSingleStmt (stmt js_ast .Stmt , kind stmtsKind ) js_ast .Stmt
(*T) visitStmts (stmts []js_ast .Stmt , kind stmtsKind ) []js_ast .Stmt
(*T) visitStmtsAndPrependTempRefs (stmts []js_ast .Stmt , opts prependTempRefsOpts ) []js_ast .Stmt
(*T) visitTSDecorators (tsDecorators []js_ast .Expr ) []js_ast .Expr
(*T) warnAboutEqualityCheck (op string , value js_ast .Expr , afterOpLoc logger .Loc ) bool
(*T) warnAboutImportNamespaceCallOrConstruct (target js_ast .Expr , isConstruct bool )
(*T) warnAboutLackOfDefine (name string , r logger .Range )
(*T) warnAboutTypeofAndString (a js_ast .Expr , b js_ast .Expr )
(*T) willNeedBindingPattern () bool
As Outputs Of (at least one unexported )
/* at least one unexported ... */ /* at least one unexported: */
func newParser (log logger .Log , source logger .Source , lexer js_lexer .Lexer , options *Options ) *parser
The pages are generated with Golds v0.3.2-preview . (GOOS=darwin GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds .