@microsoft/powerquery-parser
Advanced tools
Comparing version
@@ -17,7 +17,7 @@ import { CommonError, Result } from "."; | ||
} | ||
export declare function tryTraverse<State extends ITraversalState<ResultType>, ResultType, Node, NodesById>(state: State, nodesById: NodesById, root: Node, strategy: VisitNodeStrategy, visitNodeFn: TVisitNodeFn<State, ResultType, Node, void>, expandNodesFn: TExpandNodesFn<State, ResultType, Node, NodesById>, maybeEarlyExitFn: TEarlyExitFn<State, ResultType, Node> | undefined): Promise<TriedTraverse<ResultType>>; | ||
export declare function tryTraverseAst<State extends ITraversalState<ResultType>, ResultType>(state: State, nodeIdMapCollection: NodeIdMap.Collection, root: Ast.TNode, strategy: VisitNodeStrategy, visitNodeFn: TVisitNodeFn<State, ResultType, Ast.TNode, void>, expandNodesFn: TExpandNodesFn<State, ResultType, Ast.TNode, NodeIdMap.Collection>, maybeEarlyExitFn: TEarlyExitFn<State, ResultType, Ast.TNode> | undefined): Promise<TriedTraverse<ResultType>>; | ||
export declare function tryTraverseXor<State extends ITraversalState<ResultType>, ResultType>(state: State, nodeIdMapCollection: NodeIdMap.Collection, root: TXorNode, strategy: VisitNodeStrategy, visitNodeFn: TVisitNodeFn<State, ResultType, TXorNode, void>, expandNodesFn: TExpandNodesFn<State, ResultType, TXorNode, NodeIdMap.Collection>, maybeEarlyExitFn: TEarlyExitFn<State, ResultType, TXorNode> | undefined): Promise<TriedTraverse<ResultType>>; | ||
export declare function tryTraverse<State extends ITraversalState<ResultType>, ResultType, Node, NodesById>(state: State, nodesById: NodesById, root: Node, strategy: VisitNodeStrategy, visitNodeFn: TVisitNodeFn<State, ResultType, Node, void>, expandNodesFn: TExpandNodesFn<State, ResultType, Node, NodesById>, maybeEarlyExitFn: TEarlyExitFn<State, ResultType, Node> | undefined): Promise<TriedTraverse<ResultType>>; | ||
export declare function assertGetAllAstChildren<State extends ITraversalState<ResultType>, ResultType>(_state: State, astNode: Ast.TNode, nodeIdMapCollection: NodeIdMap.Collection): Promise<ReadonlyArray<Ast.TNode>>; | ||
export declare function assertGetAllXorChildren<State extends ITraversalState<ResultType>, ResultType>(_state: State, xorNode: TXorNode, nodeIdMapCollection: NodeIdMap.Collection): Promise<ReadonlyArray<TXorNode>>; | ||
export declare function maybeExpandXorParent<T>(_state: T, xorNode: TXorNode, nodeIdMapCollection: NodeIdMap.Collection): Promise<ReadonlyArray<TXorNode>>; |
@@ -14,7 +14,16 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.maybeExpandXorParent = exports.assertGetAllXorChildren = exports.assertGetAllAstChildren = exports.tryTraverse = exports.tryTraverseXor = exports.tryTraverseAst = void 0; | ||
exports.maybeExpandXorParent = exports.assertGetAllXorChildren = exports.assertGetAllAstChildren = exports.tryTraverseXor = exports.tryTraverseAst = exports.tryTraverse = void 0; | ||
const _1 = require("."); | ||
const parser_1 = require("../parser"); | ||
const result_1 = require("./result"); | ||
// sets Node and NodesById for tryTraverse | ||
// Most commonly used by visiting all nodes (either Ast or TXorNode) with the visitNodeFn, | ||
// It usually expands all children nodes but can expand the list of nodes to visit through other logic. | ||
function tryTraverse(state, nodesById, root, strategy, visitNodeFn, expandNodesFn, maybeEarlyExitFn) { | ||
return result_1.ResultUtils.ensureResultAsync(() => __awaiter(this, void 0, void 0, function* () { | ||
yield traverseRecursion(state, nodesById, root, strategy, visitNodeFn, expandNodesFn, maybeEarlyExitFn, state.maybeInitialCorrelationId); | ||
return state.result; | ||
}), state.locale); | ||
} | ||
exports.tryTraverse = tryTraverse; | ||
// sets the tryTraverse type parameters: Node and NodesById | ||
function tryTraverseAst(state, nodeIdMapCollection, root, strategy, visitNodeFn, expandNodesFn, maybeEarlyExitFn) { | ||
@@ -24,3 +33,3 @@ return tryTraverse(state, nodeIdMapCollection, root, strategy, visitNodeFn, expandNodesFn, maybeEarlyExitFn); | ||
exports.tryTraverseAst = tryTraverseAst; | ||
// sets Node and NodesById for tryTraverse | ||
// sets the tryTraverse type parameters: Node and NodesById | ||
function tryTraverseXor(state, nodeIdMapCollection, root, strategy, visitNodeFn, expandNodesFn, maybeEarlyExitFn) { | ||
@@ -30,10 +39,3 @@ return tryTraverse(state, nodeIdMapCollection, root, strategy, visitNodeFn, expandNodesFn, maybeEarlyExitFn); | ||
exports.tryTraverseXor = tryTraverseXor; | ||
function tryTraverse(state, nodesById, root, strategy, visitNodeFn, expandNodesFn, maybeEarlyExitFn) { | ||
return result_1.ResultUtils.ensureResultAsync(() => __awaiter(this, void 0, void 0, function* () { | ||
yield traverseRecursion(state, nodesById, root, strategy, visitNodeFn, expandNodesFn, maybeEarlyExitFn, state.maybeInitialCorrelationId); | ||
return state.result; | ||
}), state.locale); | ||
} | ||
exports.tryTraverse = tryTraverse; | ||
// a TExpandNodesFn usable by tryTraverseAst which visits all nodes. | ||
// a TExpandNodesFn usable by tryTraverseAst which visits all Ast nodes. | ||
// eslint-disable-next-line require-await | ||
@@ -87,2 +89,3 @@ function assertGetAllAstChildren(_state, astNode, nodeIdMapCollection) { | ||
exports.maybeExpandXorParent = maybeExpandXorParent; | ||
// The core logic of a traversal. | ||
function traverseRecursion(state, nodesById, node, strategy, visitNodeFn, expandNodesFn, maybeEarlyExitFn, maybeCorrelationId) { | ||
@@ -89,0 +92,0 @@ var _a; |
@@ -99,4 +99,4 @@ "use strict"; | ||
exports.typeCheckTable = typeCheckTable; | ||
function typeCheckGenericNumber(valueElements, schemaItemTypes, valueCmpFn, traceManager, maybeCorrelationId) { | ||
const trace = traceManager.entry("TypeCheck" /* TypeCheck */, typeCheckGenericNumber.name, maybeCorrelationId); | ||
function typeCheckGenericNumber(valueElements, schemaItemTypes, valueCmpFn, traceManager, correlationId) { | ||
const trace = traceManager.entry("TypeCheck" /* TypeCheck */, typeCheckGenericNumber.name, correlationId); | ||
const numElements = valueElements.length; | ||
@@ -103,0 +103,0 @@ const numItemTypes = schemaItemTypes.length; |
@@ -56,2 +56,3 @@ "use strict"; | ||
exports.trySnapshot = trySnapshot; | ||
const ErrorMessageNoEndToken = "once a multiline token starts it should either reach a paired end token, or eof"; | ||
function createSnapshot(state) { | ||
@@ -142,3 +143,3 @@ var _a; | ||
const details = { foundTokenEnd: maybeTokenEnd }; | ||
const message = `once a multiline token starts it should either reach a paired end token, or eof`; | ||
const message = ErrorMessageNoEndToken; | ||
throw new common_1.CommonError.InvariantError(message, details); | ||
@@ -170,3 +171,3 @@ } | ||
const details = { foundTokenEnd: maybeTokenEnd }; | ||
const message = `once a multiline token starts it should either reach a paired end token, or eof`; | ||
const message = ErrorMessageNoEndToken; | ||
throw new common_1.CommonError.InvariantError(message, details); | ||
@@ -197,3 +198,3 @@ } | ||
const details = { foundTokenEnd: maybeTokenEnd }; | ||
const message = `once a multiline token starts it should either reach a paired end token, or eof`; | ||
const message = ErrorMessageNoEndToken; | ||
throw new common_1.CommonError.InvariantError(message, details); | ||
@@ -200,0 +201,0 @@ } |
@@ -22,3 +22,3 @@ "use strict"; | ||
// Mutates the given state to whatever parse state which matched the most amount of tokens. | ||
// Ties are resolved in the order of the given parse functions. | ||
// Ties are resolved by the ordering of the given parse functions. | ||
function readAmbiguous(state, parser, parseFns, maybeCorrelationId) { | ||
@@ -25,0 +25,0 @@ return __awaiter(this, void 0, void 0, function* () { |
import { NodeIdMap } from "."; | ||
import { TXorNode, XorNode } from "./xorNode"; | ||
import { Ast } from "../../language"; | ||
export declare function assertGetAncestry(nodeIdMapCollection: NodeIdMap.Collection, rootId: number): ReadonlyArray<TXorNode>; | ||
export declare function assertGetAncestry(nodeIdMapCollection: NodeIdMap.Collection, nodeId: number): ReadonlyArray<TXorNode>; | ||
export declare function assertGetLeaf(ancestry: ReadonlyArray<TXorNode>): TXorNode; | ||
@@ -6,0 +6,0 @@ export declare function assertGetLeafChecked<T extends Ast.TNode>(ancestry: ReadonlyArray<TXorNode>, expectedNodeKinds: ReadonlyArray<T["kind"]> | T["kind"]): XorNode<T>; |
@@ -8,5 +8,6 @@ "use strict"; | ||
const common_1 = require("../../common"); | ||
function assertGetAncestry(nodeIdMapCollection, rootId) { | ||
const ancestryIds = [rootId]; | ||
let maybeParentId = nodeIdMapCollection.parentIdById.get(rootId); | ||
// Builds up an TXorNode path starting from nodeId and goes up to the root of the Ast. | ||
function assertGetAncestry(nodeIdMapCollection, nodeId) { | ||
const ancestryIds = [nodeId]; | ||
let maybeParentId = nodeIdMapCollection.parentIdById.get(nodeId); | ||
while (maybeParentId) { | ||
@@ -13,0 +14,0 @@ const parentId = maybeParentId; |
@@ -32,3 +32,3 @@ import { Ast } from "../../language"; | ||
export declare function maybeNextSiblingXor(nodeIdMapCollection: NodeIdMap.Collection, nodeId: number): TXorNode | undefined; | ||
export declare function maybeNthSiblingXor(nodeIdMapCollection: NodeIdMap.Collection, rootId: number, offset: number): TXorNode | undefined; | ||
export declare function maybeNthSiblingXor(nodeIdMapCollection: NodeIdMap.Collection, nodeId: number, offset: number): TXorNode | undefined; | ||
export declare function iterArrayWrapper(nodeIdMapCollection: NodeIdMap.Collection, arrayWrapper: TXorNode): ReadonlyArray<TXorNode>; | ||
@@ -35,0 +35,0 @@ export declare function iterFieldProjection(nodeIdMapCollection: NodeIdMap.Collection, fieldProjection: TXorNode): ReadonlyArray<TXorNode>; |
@@ -59,4 +59,4 @@ "use strict"; | ||
// (givenNode.maybeAttributeIndex + offset) as an XorNode if such a child exists. | ||
function maybeNthSiblingXor(nodeIdMapCollection, rootId, offset) { | ||
const childXorNode = _1.NodeIdMapUtils.assertGetXor(nodeIdMapCollection, rootId); | ||
function maybeNthSiblingXor(nodeIdMapCollection, nodeId, offset) { | ||
const childXorNode = _1.NodeIdMapUtils.assertGetXor(nodeIdMapCollection, nodeId); | ||
if (childXorNode.node.maybeAttributeIndex === undefined) { | ||
@@ -69,3 +69,3 @@ return undefined; | ||
} | ||
const parentXorNode = _1.NodeIdMapUtils.assertGetParentXor(nodeIdMapCollection, rootId); | ||
const parentXorNode = _1.NodeIdMapUtils.assertGetParentXor(nodeIdMapCollection, nodeId); | ||
const childIds = assertIterChildIds(nodeIdMapCollection.childIdsById, parentXorNode.node.id); | ||
@@ -141,3 +141,3 @@ if (childIds.length >= attributeIndex) { | ||
for (const parameter of iterFunctionExpressionParameters(nodeIdMapCollection, functionExpression)) { | ||
const maybeName = (0, nodeIdMapUtils_1.maybeParameterName)(nodeIdMapCollection, parameter); | ||
const maybeName = (0, nodeIdMapUtils_1.maybeUnboxIdentifier)(nodeIdMapCollection, parameter); | ||
if (maybeName === undefined) { | ||
@@ -144,0 +144,0 @@ break; |
@@ -5,3 +5,3 @@ import { NodeIdMap } from ".."; | ||
import { TXorNode } from "../xorNode"; | ||
export declare function recalculateIds(traceManager: TraceManager, nodeIdMapCollection: NodeIdMap.Collection, nodeStart: TXorNode, maybeCorrelationId: number | undefined): Map<number, number>; | ||
export declare function updateNodeIds(traceManager: TraceManager, nodeIdMapCollection: Collection, newIdByOldId: Map<number, number>, maybeCorrelationId: number | undefined): void; | ||
export declare function recalculateIds(nodeIdMapCollection: NodeIdMap.Collection, nodeStart: TXorNode, traceManager: TraceManager, maybeCorrelationId: number | undefined): Map<number, number>; | ||
export declare function updateNodeIds(nodeIdMapCollection: Collection, newIdByOldId: Map<number, number>, traceManager: TraceManager, maybeCorrelationId: number | undefined): void; |
@@ -9,6 +9,6 @@ "use strict"; | ||
// Helper functions which are related to updating / remapping nodeIds for NodeIdMap.Collection | ||
// Returns a map of `oldId -> newId` which follows the ID ordering invariant, | ||
// expected to be consumed by updateNodeIds. | ||
// Returns a map of `oldId -> newId` which follows the ID ordering invariant. | ||
// Expected to be immediately consumed by updateNodeIds. | ||
// Used to restore the nodeId ordering invariant after manual mangling of the Ast. | ||
function recalculateIds(traceManager, nodeIdMapCollection, nodeStart, maybeCorrelationId) { | ||
function recalculateIds(nodeIdMapCollection, nodeStart, traceManager, maybeCorrelationId) { | ||
const trace = traceManager.entry("IdUtils" /* IdUtils */, recalculateIds.name, maybeCorrelationId); | ||
@@ -35,3 +35,3 @@ const visitedXorNodes = []; | ||
// Assumes the given arguments are valid as this function does no validation. | ||
function updateNodeIds(traceManager, nodeIdMapCollection, newIdByOldId, maybeCorrelationId) { | ||
function updateNodeIds(nodeIdMapCollection, newIdByOldId, traceManager, maybeCorrelationId) { | ||
const trace = traceManager.entry("IdUtils" /* IdUtils */, updateNodeIds.name, maybeCorrelationId, { | ||
@@ -49,8 +49,8 @@ ["MapSize" /* MapSize */]: newIdByOldId.size, | ||
// Storage for the change delta which is used to mutate nodeIdMapCollection. | ||
const partialDelta = createDelta(traceManager, nodeIdMapCollection, newIdByOldId, xorNodes, trace.id); | ||
applyDelta(traceManager, nodeIdMapCollection, newIdByOldId, xorNodes, partialDelta, trace.id); | ||
const partialDelta = createDelta(nodeIdMapCollection, newIdByOldId, xorNodes, traceManager, trace.id); | ||
applyDelta(nodeIdMapCollection, newIdByOldId, xorNodes, partialDelta, traceManager, trace.id); | ||
trace.exit(); | ||
} | ||
exports.updateNodeIds = updateNodeIds; | ||
function createDelta(traceManager, nodeIdMapCollection, newIdByOldId, xorNodes, correlationId) { | ||
function createDelta(nodeIdMapCollection, newIdByOldId, xorNodes, traceManager, correlationId) { | ||
var _a; | ||
@@ -101,3 +101,3 @@ const trace = traceManager.entry("IdUtils" /* IdUtils */, createDelta.name, correlationId, { | ||
} | ||
function applyDelta(traceManager, nodeIdMapCollection, newIdByOldId, xorNodes, delta, correlationId) { | ||
function applyDelta(nodeIdMapCollection, newIdByOldId, xorNodes, delta, traceManager, correlationId) { | ||
var _a, _b; | ||
@@ -104,0 +104,0 @@ const trace = traceManager.entry("IdUtils" /* IdUtils */, applyDelta.name, correlationId); |
@@ -9,3 +9,3 @@ import { Collection } from "../nodeIdMap"; | ||
export declare function maybeLeftMostLeaf(nodeIdMapCollection: NodeIdMap.Collection, nodeId: number): Ast.TNode | undefined; | ||
export declare function maybeRightMostLeaf(nodeIdMapCollection: Collection, rootId: number, maybeCondition?: ((node: Ast.TNode) => boolean) | undefined): Promise<Ast.TNode | undefined>; | ||
export declare function maybeRightMostLeafWhere(nodeIdMapCollection: Collection, rootId: number, maybeCondition: ((node: Ast.TNode) => boolean) | undefined): Promise<Ast.TNode | undefined>; | ||
export declare function maybeRightMostLeaf(nodeIdMapCollection: Collection, nodeId: number, maybeCondition?: ((node: Ast.TNode) => boolean) | undefined): Promise<Ast.TNode | undefined>; | ||
export declare function maybeRightMostLeafWhere(nodeIdMapCollection: Collection, nodeId: number, maybeCondition: ((node: Ast.TNode) => boolean) | undefined): Promise<Ast.TNode | undefined>; |
@@ -17,2 +17,3 @@ "use strict"; | ||
exports.assertGetLeftMostXor = assertGetLeftMostXor; | ||
// Travels down the left most node under the given nodeId by way of the children collection. | ||
function maybeLeftMostXor(nodeIdMapCollection, nodeId) { | ||
@@ -32,2 +33,3 @@ const currentNode = (0, commonSelectors_1.maybeXor)(nodeIdMapCollection, nodeId); | ||
exports.maybeLeftMostXor = maybeLeftMostXor; | ||
// Same as maybeLeftMostXor but also checks if it's an Ast node. | ||
function maybeLeftMostLeaf(nodeIdMapCollection, nodeId) { | ||
@@ -42,5 +44,5 @@ const maybeXorNode = maybeLeftMostXor(nodeIdMapCollection, nodeId); | ||
// * Therefore the right-most child is the most recently read which also appears last in the document. | ||
function maybeRightMostLeaf(nodeIdMapCollection, rootId, maybeCondition = undefined) { | ||
function maybeRightMostLeaf(nodeIdMapCollection, nodeId, maybeCondition = undefined) { | ||
const astNodeById = nodeIdMapCollection.astNodeById; | ||
let nodeIdsToExplore = [rootId]; | ||
let nodeIdsToExplore = [nodeId]; | ||
let maybeRightMost; | ||
@@ -99,6 +101,6 @@ while (nodeIdsToExplore.length) { | ||
exports.maybeRightMostLeaf = maybeRightMostLeaf; | ||
function maybeRightMostLeafWhere(nodeIdMapCollection, rootId, maybeCondition) { | ||
return maybeRightMostLeaf(nodeIdMapCollection, rootId, maybeCondition); | ||
function maybeRightMostLeafWhere(nodeIdMapCollection, nodeId, maybeCondition) { | ||
return maybeRightMostLeaf(nodeIdMapCollection, nodeId, maybeCondition); | ||
} | ||
exports.maybeRightMostLeafWhere = maybeRightMostLeafWhere; | ||
//# sourceMappingURL=leafSelectors.js.map |
@@ -28,6 +28,6 @@ "use strict"; | ||
astNodeById: new Map(nodeIdMapCollection.astNodeById), | ||
childIdsById: new Map(nodeIdMapCollection.childIdsById), | ||
contextNodeById, | ||
childIdsById: new Map(nodeIdMapCollection.childIdsById), | ||
leafIds: new Set(nodeIdMapCollection.leafIds), | ||
idsByNodeKind, | ||
leafIds: new Set(nodeIdMapCollection.leafIds), | ||
maybeRightMostLeaf: nodeIdMapCollection.maybeRightMostLeaf, | ||
@@ -38,3 +38,3 @@ parentIdById: new Map(nodeIdMapCollection.parentIdById), | ||
exports.copy = copy; | ||
// Contains at least one parsed token. | ||
// Checks if the given nodeId contains at least one parsed token. | ||
function hasParsedToken(nodeIdMapCollection, nodeId) { | ||
@@ -70,2 +70,3 @@ let maybeChildIds = nodeIdMapCollection.childIdsById.get(nodeId); | ||
exports.hasParsedToken = hasParsedToken; | ||
// Return a XorNodeTokenRange for the given TXorNode. | ||
function xorNodeTokenRange(nodeIdMapCollection, xorNode) { | ||
@@ -72,0 +73,0 @@ return __awaiter(this, void 0, void 0, function* () { |
@@ -6,4 +6,4 @@ import { NodeIdMap } from ".."; | ||
export declare function maybeInvokeExpressionIdentifier(nodeIdMapCollection: NodeIdMap.Collection, nodeId: number): XorNode<Ast.IdentifierExpression> | undefined; | ||
export declare function maybeParameterName(nodeIdMapCollection: NodeIdMap.Collection, functionParameter: TXorNode): Ast.Identifier | undefined; | ||
export declare function maybeParameterNameLiteral(nodeIdMapCollection: NodeIdMap.Collection, functionParameter: TXorNode): string | undefined; | ||
export declare function maybeUnboxIdentifier(nodeIdMapCollection: NodeIdMap.Collection, functionParameter: TXorNode): Ast.Identifier | undefined; | ||
export declare function maybeUnboxIdentifierLiteral(nodeIdMapCollection: NodeIdMap.Collection, functionParameter: TXorNode): string | undefined; | ||
export declare function maybeInvokeExpressionIdentifierLiteral(nodeIdMapCollection: NodeIdMap.Collection, nodeId: number): string | undefined; |
@@ -5,3 +5,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.maybeInvokeExpressionIdentifierLiteral = exports.maybeParameterNameLiteral = exports.maybeParameterName = exports.maybeInvokeExpressionIdentifier = exports.assertGetRecursiveExpressionPreviousSibling = void 0; | ||
exports.maybeInvokeExpressionIdentifierLiteral = exports.maybeUnboxIdentifierLiteral = exports.maybeUnboxIdentifier = exports.maybeInvokeExpressionIdentifier = exports.assertGetRecursiveExpressionPreviousSibling = void 0; | ||
const childSelectors_1 = require("./childSelectors"); | ||
@@ -14,2 +14,3 @@ const parentSelectors_1 = require("./parentSelectors"); | ||
// Commonly used for things like getting the identifier name used in an InvokeExpression. | ||
// Returns undefined if there is no previous sibling. | ||
function assertGetRecursiveExpressionPreviousSibling(nodeIdMapCollection, nodeId, maybeExpectedNodeKinds) { | ||
@@ -44,2 +45,4 @@ const xorNode = (0, commonSelectors_1.assertGetXor)(nodeIdMapCollection, nodeId); | ||
exports.assertGetRecursiveExpressionPreviousSibling = assertGetRecursiveExpressionPreviousSibling; | ||
// Asserts the given node is an InvokeExpression, | ||
// then returns the previous sibling on the condition that it's an identifier. | ||
function maybeInvokeExpressionIdentifier(nodeIdMapCollection, nodeId) { | ||
@@ -73,11 +76,14 @@ const invokeExprXorNode = (0, commonSelectors_1.assertGetXorChecked)(nodeIdMapCollection, nodeId, "InvokeExpression" /* InvokeExpression */); | ||
exports.maybeInvokeExpressionIdentifier = maybeInvokeExpressionIdentifier; | ||
function maybeParameterName(nodeIdMapCollection, functionParameter) { | ||
// Unboxes the node if it's a identifier | ||
function maybeUnboxIdentifier(nodeIdMapCollection, functionParameter) { | ||
return (0, childSelectors_1.maybeUnboxNthChildIfAstChecked)(nodeIdMapCollection, functionParameter.node.id, 1, "Identifier" /* Identifier */); | ||
} | ||
exports.maybeParameterName = maybeParameterName; | ||
function maybeParameterNameLiteral(nodeIdMapCollection, functionParameter) { | ||
const maybeIdentifier = maybeParameterName(nodeIdMapCollection, functionParameter); | ||
exports.maybeUnboxIdentifier = maybeUnboxIdentifier; | ||
// Unboxes the identifier literal if it exists. | ||
function maybeUnboxIdentifierLiteral(nodeIdMapCollection, functionParameter) { | ||
const maybeIdentifier = maybeUnboxIdentifier(nodeIdMapCollection, functionParameter); | ||
return maybeIdentifier ? maybeIdentifier.literal : undefined; | ||
} | ||
exports.maybeParameterNameLiteral = maybeParameterNameLiteral; | ||
exports.maybeUnboxIdentifierLiteral = maybeUnboxIdentifierLiteral; | ||
// Unboxes the identifier literal for function name if it exists. | ||
function maybeInvokeExpressionIdentifierLiteral(nodeIdMapCollection, nodeId) { | ||
@@ -84,0 +90,0 @@ (0, commonSelectors_1.assertGetXorChecked)(nodeIdMapCollection, nodeId, "InvokeExpression" /* InvokeExpression */); |
@@ -6,4 +6,4 @@ import { ParseStateCheckpoint, TriedParse } from "./parser"; | ||
export declare function tryParse(parseSettings: ParseSettings, lexerSnapshot: LexerSnapshot): Promise<TriedParse>; | ||
export declare function tryParseDocument(parseSettings: ParseSettings, lexerSnapshot: LexerSnapshot, maybeCorrelationId: number | undefined): Promise<TriedParse>; | ||
export declare function tryParseDocument(parseSettings: ParseSettings, lexerSnapshot: LexerSnapshot): Promise<TriedParse>; | ||
export declare function createCheckpoint(state: ParseState): Promise<ParseStateCheckpoint>; | ||
export declare function restoreCheckpoint(state: ParseState, checkpoint: ParseStateCheckpoint): Promise<void>; |
@@ -23,9 +23,10 @@ "use strict"; | ||
const trace = parseSettings.traceManager.entry("ParserUtils" /* ParserUtils */, tryParse.name, parseSettings.maybeInitialCorrelationId); | ||
const maybeParserEntryPointFn = parseSettings === null || parseSettings === void 0 ? void 0 : parseSettings.maybeParserEntryPointFn; | ||
const updatedSettings = Object.assign(Object.assign({}, parseSettings), { maybeInitialCorrelationId: trace.id }); | ||
const maybeParserEntryPointFn = updatedSettings === null || updatedSettings === void 0 ? void 0 : updatedSettings.maybeParserEntryPointFn; | ||
if (maybeParserEntryPointFn === undefined) { | ||
return yield tryParseDocument(parseSettings, lexerSnapshot, trace.id); | ||
return yield tryParseDocument(updatedSettings, lexerSnapshot); | ||
} | ||
const parseState = parseSettings.createParseState(lexerSnapshot, defaultOverrides(parseSettings)); | ||
const parseState = updatedSettings.createParseState(lexerSnapshot, defaultOverrides(updatedSettings)); | ||
try { | ||
const root = yield maybeParserEntryPointFn(parseState, parseSettings.parser, trace.id); | ||
const root = yield maybeParserEntryPointFn(parseState, updatedSettings.parser, trace.id); | ||
parseState_1.ParseStateUtils.assertIsDoneParsing(parseState); | ||
@@ -40,3 +41,3 @@ return common_1.ResultUtils.boxOk({ | ||
common_1.Assert.isInstanceofError(error); | ||
return common_1.ResultUtils.boxError(ensureParseError(parseState, error, parseSettings.locale)); | ||
return common_1.ResultUtils.boxError(ensureParseError(parseState, error, updatedSettings.locale)); | ||
} | ||
@@ -46,5 +47,7 @@ }); | ||
exports.tryParse = tryParse; | ||
function tryParseDocument(parseSettings, lexerSnapshot, maybeCorrelationId) { | ||
// Attempts to parse the document both as an expression and section document. | ||
// Whichever attempt consumed the most tokens is the one returned. Ties go to expression documents. | ||
function tryParseDocument(parseSettings, lexerSnapshot) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const trace = parseSettings.traceManager.entry("ParserUtils" /* ParserUtils */, tryParseDocument.name, maybeCorrelationId); | ||
const trace = parseSettings.traceManager.entry("ParserUtils" /* ParserUtils */, tryParseDocument.name, parseSettings.maybeInitialCorrelationId); | ||
let root; | ||
@@ -51,0 +54,0 @@ const expressionDocumentState = parseSettings.createParseState(lexerSnapshot, defaultOverrides(parseSettings)); |
{ | ||
"name": "@microsoft/powerquery-parser", | ||
"version": "0.8.4", | ||
"version": "0.8.5", | ||
"description": "A parser for the Power Query/M formula language.", | ||
@@ -5,0 +5,0 @@ "author": "Microsoft", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
1615445
0.09%20776
0.08%