This commit is contained in:
JordanBoltonMN 2021-12-30 20:13:43 -06:00
Родитель 0b3f84b37e
Коммит 60117b5276
43 изменённых файлов: 80 добавлений и 33 удалений

Просмотреть файл

@ -32,5 +32,12 @@ module.exports = {
"prettier/prettier": ["error"],
"security/detect-non-literal-fs-filename": "off",
"security/detect-object-injection": "off",
"sort-imports": [
"error",
{
allowSeparatedGroups: true,
ignoreCase: true,
},
],
},
};

3
.vscode/extensions.json поставляемый
Просмотреть файл

@ -1,6 +1,7 @@
{
"recommendations": [
"esbenp.prettier-vscode"
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode",
],
"unwantedRecommendations": []
}

Просмотреть файл

@ -1,8 +1,8 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
/* tslint:disable:no-console */
import * as PQP from "@microsoft/powerquery-parser";
import { FormatSettings, IndentationLiteral, NewlineLiteral, TFormatError, tryFormat } from ".";
const text: string = `1 as number`;
@ -13,6 +13,7 @@ const settings: FormatSettings = {
};
const triedFormat: PQP.Result<string, TFormatError> = tryFormat(settings, text);
/* tslint:disable:no-console */
if (PQP.ResultUtils.isOk(triedFormat)) {
console.log("Your input was formatted as the following:");
console.log(triedFormat.value);

Просмотреть файл

@ -2,6 +2,7 @@
// Licensed under the MIT license.
import * as PQP from "@microsoft/powerquery-parser";
import {
CommentCollectionMap,
IsMultilineMap,
@ -9,7 +10,6 @@ import {
tryTraverseComment,
tryTraverseSerializeParameter,
} from "./passes";
import { tryTraverseIsMultiline } from "./passes/isMultiline/isMultiline";
import {
IndentationLiteral,
NewlineLiteral,
@ -17,6 +17,7 @@ import {
SerializeSettings,
trySerialize,
} from "./serialize";
import { tryTraverseIsMultiline } from "./passes/isMultiline/isMultiline";
export type TriedFormat = PQP.Result<string, TFormatError>;

Просмотреть файл

@ -2,6 +2,7 @@
// Licensed under the MIT license.
import * as PQP from "@microsoft/powerquery-parser";
import { CommentCollection, CommentCollectionMap, CommentState } from "./commonTypes";
// TODO pass in leafIds instead for a big speed boost.

Просмотреть файл

@ -2,6 +2,7 @@
// Licensed under the MIT license.
import * as PQP from "@microsoft/powerquery-parser";
import { IsMultilineMap } from "../commonTypes";
export function expectGetIsMultiline(isMultilineMap: IsMultilineMap, node: PQP.Language.Ast.TNode): boolean {

Просмотреть файл

@ -2,8 +2,9 @@
// Licensed under the MIT license.
import * as PQP from "@microsoft/powerquery-parser";
import { FormatTraceConstant } from "../../trace";
import { CommentCollectionMap, IsMultilineMap } from "../commonTypes";
import { FormatTraceConstant } from "../../trace";
import { tryTraverseIsMultilineFirstPass } from "./isMultilineFirstPass";
import { tryTraverseIsMultilineSecondPass } from "./isMultilineSecondPass";

Просмотреть файл

@ -2,7 +2,7 @@
// Licensed under the MIT license.
import * as PQP from "@microsoft/powerquery-parser";
import { FormatTraceConstant } from "../../trace";
import {
CommentCollection,
CommentCollectionMap,
@ -11,6 +11,7 @@ import {
LinearLengthMap,
} from "../commonTypes";
import { expectGetIsMultiline, setIsMultiline } from "./common";
import { FormatTraceConstant } from "../../trace";
import { getLinearLength } from "./linearLength";
export function tryTraverseIsMultilineFirstPass(

Просмотреть файл

@ -2,9 +2,10 @@
// Licensed under the MIT license.
import * as PQP from "@microsoft/powerquery-parser";
import { FormatTraceConstant } from "../../trace";
import { IsMultilineMap, IsMultilineSecondPassState } from "../commonTypes";
import { expectGetIsMultiline, setIsMultiline } from "./common";
import { IsMultilineMap, IsMultilineSecondPassState } from "../commonTypes";
import { FormatTraceConstant } from "../../trace";
export function tryTraverseIsMultilineSecondPass(
locale: string,

Просмотреть файл

@ -2,8 +2,9 @@
// Licensed under the MIT license.
import * as PQP from "@microsoft/powerquery-parser";
import { FormatTraceConstant } from "../../trace";
import { LinearLengthMap, LinearLengthState } from "../commonTypes";
import { FormatTraceConstant } from "../../trace";
// Lazy evaluation of a potentially large PQP.Language.AST.
// Returns the length of text if the node was formatted on a single line.

Просмотреть файл

@ -2,9 +2,10 @@
// Licensed under the MIT license.
import * as PQP from "@microsoft/powerquery-parser";
import { IndentationChange, SerializeParameterState, SerializeWriteKind } from "../commonTypes";
import { expectGetIsMultiline } from "../isMultiline/common";
import { isSectionMemeberSimilarScope, propagateWriteKind, setWorkspace } from "./visitNodeUtils";
import { expectGetIsMultiline } from "../isMultiline/common";
export function visitArrayWrapper(state: SerializeParameterState, node: PQP.Language.Ast.TArrayWrapper): void {
const parent: PQP.Language.Ast.TNode = PQP.Parser.NodeIdMapUtils.assertUnboxParentAst(

Просмотреть файл

@ -2,6 +2,7 @@
// Licensed under the MIT license.
import * as PQP from "@microsoft/powerquery-parser";
import {
CommentCollection,
SerializeCommentParameter,

Просмотреть файл

@ -2,9 +2,10 @@
// Licensed under the MIT license.
import * as PQP from "@microsoft/powerquery-parser";
import { propagateWriteKind, setWorkspace } from "./visitNodeUtils";
import { SerializeParameterState, SerializeWriteKind } from "../commonTypes";
import { expectGetIsMultiline } from "../isMultiline/common";
import { propagateWriteKind, setWorkspace } from "./visitNodeUtils";
export function visitErrorHandlingExpression(
state: SerializeParameterState,

Просмотреть файл

@ -2,9 +2,10 @@
// Licensed under the MIT license.
import * as PQP from "@microsoft/powerquery-parser";
import { propagateWriteKind, setWorkspace } from "./visitNodeUtils";
import { SerializeParameter, SerializeParameterState, SerializeWriteKind } from "../commonTypes";
import { expectGetIsMultiline } from "../isMultiline/common";
import { propagateWriteKind, setWorkspace } from "./visitNodeUtils";
// TPairedConstant override
export function visitErrorRaisingExpression(

Просмотреть файл

@ -2,9 +2,10 @@
// Licensed under the MIT license.
import * as PQP from "@microsoft/powerquery-parser";
import { maybePropagateWriteKind, propagateWriteKind, setWorkspace } from "./visitNodeUtils";
import { SerializeParameter, SerializeParameterState, SerializeWriteKind } from "../commonTypes";
import { expectGetIsMultiline } from "../isMultiline/common";
import { maybePropagateWriteKind, propagateWriteKind, setWorkspace } from "./visitNodeUtils";
// TPairedConstant override
export function visitFieldSpecification(

Просмотреть файл

@ -2,6 +2,7 @@
// Licensed under the MIT license.
import * as PQP from "@microsoft/powerquery-parser";
import { SerializeParameter, SerializeParameterState, SerializeWriteKind } from "../commonTypes";
import { expectGetIsMultiline } from "../isMultiline/common";
import { setWorkspace } from "./visitNodeUtils";

Просмотреть файл

@ -2,8 +2,9 @@
// Licensed under the MIT license.
import * as PQP from "@microsoft/powerquery-parser";
import { SerializeParameter, SerializeParameterState, SerializeWriteKind } from "../commonTypes";
import { getWorkspace, propagateWriteKind, setWorkspace } from "./visitNodeUtils";
import { SerializeParameter, SerializeParameterState, SerializeWriteKind } from "../commonTypes";
export function visitFieldTypeSpecification(
state: SerializeParameterState,

Просмотреть файл

@ -2,9 +2,10 @@
// Licensed under the MIT license.
import * as PQP from "@microsoft/powerquery-parser";
import { propagateWriteKind, setWorkspace } from "./visitNodeUtils";
import { SerializeParameter, SerializeParameterState, SerializeWriteKind } from "../commonTypes";
import { expectGetIsMultiline } from "../isMultiline/common";
import { propagateWriteKind, setWorkspace } from "./visitNodeUtils";
export function visitFunctionExpression(
state: SerializeParameterState,

Просмотреть файл

@ -2,8 +2,9 @@
// Licensed under the MIT license.
import * as PQP from "@microsoft/powerquery-parser";
import { SerializeParameter, SerializeParameterState, SerializeWriteKind } from "../commonTypes";
import { propagateWriteKind, setWorkspace } from "./visitNodeUtils";
import { SerializeParameter, SerializeParameterState, SerializeWriteKind } from "../commonTypes";
export function visitFunctionType(state: SerializeParameterState, node: PQP.Language.Ast.FunctionType): void {
propagateWriteKind(state, node, node.functionConstant);

Просмотреть файл

@ -2,6 +2,7 @@
// Licensed under the MIT license.
import * as PQP from "@microsoft/powerquery-parser";
import { DefaultSerializeParameter, SerializeParameterState } from "../commonTypes";
import { maybePropagateWriteKind, propagateWriteKind, setWorkspace } from "./visitNodeUtils";

Просмотреть файл

@ -2,9 +2,10 @@
// Licensed under the MIT license.
import * as PQP from "@microsoft/powerquery-parser";
import { propagateWriteKind, setWorkspace } from "./visitNodeUtils";
import { SerializeParameter, SerializeParameterState, SerializeWriteKind } from "../commonTypes";
import { expectGetIsMultiline } from "../isMultiline/common";
import { propagateWriteKind, setWorkspace } from "./visitNodeUtils";
export function visitIfExpression(state: SerializeParameterState, node: PQP.Language.Ast.IfExpression): void {
propagateWriteKind(state, node, node.ifConstant);

Просмотреть файл

@ -2,6 +2,7 @@
// Licensed under the MIT license.
import * as PQP from "@microsoft/powerquery-parser";
import { IsMultilineMap, SerializeParameter, SerializeParameterState, SerializeWriteKind } from "../commonTypes";
import { expectGetIsMultiline } from "../isMultiline/common";
import { setWorkspace } from "./visitNodeUtils";

Просмотреть файл

@ -2,9 +2,10 @@
// Licensed under the MIT license.
import * as PQP from "@microsoft/powerquery-parser";
import { getWorkspace, maybeSetIndentationChange } from "./visitNodeUtils";
import { SerializeParameter, SerializeParameterState, SerializeWriteKind } from "../commonTypes";
import { visitComments } from "./visitComments";
import { getWorkspace, maybeSetIndentationChange } from "./visitNodeUtils";
export function visitLeaf(
state: SerializeParameterState,

Просмотреть файл

@ -2,8 +2,9 @@
// Licensed under the MIT license.
import * as PQP from "@microsoft/powerquery-parser";
import { SerializeParameterState, SerializeWriteKind } from "../commonTypes";
import { propagateWriteKind, setWorkspace } from "./visitNodeUtils";
import { SerializeParameterState, SerializeWriteKind } from "../commonTypes";
export function visitLetExpression(state: SerializeParameterState, node: PQP.Language.Ast.LetExpression): void {
propagateWriteKind(state, node, node.letConstant);

Просмотреть файл

@ -2,6 +2,7 @@
// Licensed under the MIT license.
import * as PQP from "@microsoft/powerquery-parser";
import { SerializeParameterState, SerializeWriteKind } from "../commonTypes";
import { expectGetIsMultiline } from "../isMultiline/common";
import { setWorkspace } from "./visitNodeUtils";

Просмотреть файл

@ -2,9 +2,10 @@
// Licensed under the MIT license.
import * as PQP from "@microsoft/powerquery-parser";
import { propagateWriteKind, setWorkspace } from "./visitNodeUtils";
import { SerializeParameter, SerializeParameterState, SerializeWriteKind } from "../commonTypes";
import { expectGetIsMultiline } from "../isMultiline/common";
import { propagateWriteKind, setWorkspace } from "./visitNodeUtils";
export function visitMetadataExpression(
state: SerializeParameterState,

Просмотреть файл

@ -2,9 +2,10 @@
// Licensed under the MIT license.
import * as PQP from "@microsoft/powerquery-parser";
import { SerializeParameter, SerializeParameterState } from "../commonTypes";
import { getWorkspace, propagateWriteKind, setWorkspace } from "./visitNodeUtils";
import { getWorkspace, propagateWriteKind, setWorkspace } from "./visitNodeUtils";
import { SerializeParameter, SerializeParameterState } from "../commonTypes";
import { FormatTraceConstant } from "../../trace";
import { visitArrayWrapper } from "./visitArrayWrapper";
import { visitErrorHandlingExpression } from "./visitErrorHandlingExpression";
import { visitErrorRaisingExpression } from "./visitErrorRaisingExpression";
@ -33,7 +34,6 @@ import { visitTParameter } from "./visitTParameter";
import { visitTWrapped } from "./visitTWrapped";
import { visitTypePrimaryType } from "./visitTypePrimaryType";
import { visitUnaryExpression } from "./visitUnaryExpression";
import { FormatTraceConstant } from "../../trace";
export function visitNode(state: SerializeParameterState, node: PQP.Language.Ast.TNode): void {
const trace: PQP.Trace.Trace = state.traceManager.entry(FormatTraceConstant.SerializeParameter, visitNode.name, {

Просмотреть файл

@ -2,6 +2,7 @@
// Licensed under the MIT license.
import * as PQP from "@microsoft/powerquery-parser";
import {
DefaultSerializeParameter,
IndentationChange,

Просмотреть файл

@ -2,6 +2,7 @@
// Licensed under the MIT license.
import * as PQP from "@microsoft/powerquery-parser";
import { SerializeParameterState, SerializeWriteKind } from "../commonTypes";
import { expectGetIsMultiline } from "../isMultiline/common";
import { setWorkspace } from "./visitNodeUtils";

Просмотреть файл

@ -2,8 +2,9 @@
// Licensed under the MIT license.
import * as PQP from "@microsoft/powerquery-parser";
import { SerializeParameter, SerializeParameterState, SerializeWriteKind } from "../commonTypes";
import { getWorkspace, propagateWriteKind, setWorkspace } from "./visitNodeUtils";
import { SerializeParameter, SerializeParameterState, SerializeWriteKind } from "../commonTypes";
export function visitRangeExpression(state: SerializeParameterState, node: PQP.Language.Ast.RangeExpression): void {
const workspace: SerializeParameter = getWorkspace(state, node);

Просмотреть файл

@ -2,6 +2,7 @@
// Licensed under the MIT license.
import * as PQP from "@microsoft/powerquery-parser";
import { IsMultilineMap, SerializeParameterState, SerializeWriteKind } from "../commonTypes";
import { expectGetIsMultiline } from "../isMultiline/common";
import { setWorkspace } from "./visitNodeUtils";

Просмотреть файл

@ -2,9 +2,10 @@
// Licensed under the MIT license.
import * as PQP from "@microsoft/powerquery-parser";
import { IsMultilineMap, SerializeParameterState, SerializeWriteKind } from "../commonTypes";
import { expectGetIsMultiline } from "../isMultiline/common";
import { propagateWriteKind, setWorkspace } from "./visitNodeUtils";
import { expectGetIsMultiline } from "../isMultiline/common";
export function visitSectionMember(state: SerializeParameterState, node: PQP.Language.Ast.SectionMember): void {
const isMultilineMap: IsMultilineMap = state.isMultilineMap;

Просмотреть файл

@ -2,9 +2,10 @@
// Licensed under the MIT license.
import * as PQP from "@microsoft/powerquery-parser";
import { propagateWriteKind, setWorkspace } from "./visitNodeUtils";
import { SerializeParameterState, SerializeWriteKind } from "../commonTypes";
import { expectGetIsMultiline } from "../isMultiline/common";
import { propagateWriteKind, setWorkspace } from "./visitNodeUtils";
export function visitTBinOpExpression(state: SerializeParameterState, node: PQP.Language.Ast.TBinOpExpression): void {
propagateWriteKind(state, node, node.left);

Просмотреть файл

@ -2,8 +2,9 @@
// Licensed under the MIT license.
import * as PQP from "@microsoft/powerquery-parser";
import { SerializeParameter, SerializeParameterState, SerializeWriteKind } from "../commonTypes";
import { getWorkspace, propagateWriteKind, setWorkspace } from "./visitNodeUtils";
import { SerializeParameter, SerializeParameterState, SerializeWriteKind } from "../commonTypes";
export function visitTCsv(state: SerializeParameterState, node: PQP.Language.Ast.TCsv): void {
const workspace: SerializeParameter = getWorkspace(state, node);

Просмотреть файл

@ -2,9 +2,10 @@
// Licensed under the MIT license.
import * as PQP from "@microsoft/powerquery-parser";
import { IsMultilineMap, SerializeParameter, SerializeParameterState, SerializeWriteKind } from "../commonTypes";
import { expectGetIsMultiline } from "../isMultiline/common";
import { propagateWriteKind, setWorkspace } from "./visitNodeUtils";
import { expectGetIsMultiline } from "../isMultiline/common";
export function visitTKeyValuePair(state: SerializeParameterState, node: PQP.Language.Ast.TKeyValuePair): void {
const isMultilineMap: IsMultilineMap = state.isMultilineMap;

Просмотреть файл

@ -2,9 +2,10 @@
// Licensed under the MIT license.
import * as PQP from "@microsoft/powerquery-parser";
import { propagateWriteKind, setWorkspace } from "./visitNodeUtils";
import { SerializeParameterState, SerializeWriteKind } from "../commonTypes";
import { expectGetIsMultiline } from "../isMultiline/common";
import { propagateWriteKind, setWorkspace } from "./visitNodeUtils";
export function visitTPairedConstant(state: SerializeParameterState, node: PQP.Language.Ast.TPairedConstant): void {
propagateWriteKind(state, node, node.constant);

Просмотреть файл

@ -2,6 +2,7 @@
// Licensed under the MIT license.
import * as PQP from "@microsoft/powerquery-parser";
import { SerializeParameterState, SerializeWriteKind } from "../commonTypes";
import { setWorkspace } from "./visitNodeUtils";

Просмотреть файл

@ -2,9 +2,10 @@
// Licensed under the MIT license.
import * as PQP from "@microsoft/powerquery-parser";
import { getWorkspace, propagateWriteKind, setWorkspace } from "./visitNodeUtils";
import { SerializeParameter, SerializeParameterState, SerializeWriteKind } from "../commonTypes";
import { expectGetIsMultiline } from "../isMultiline/common";
import { getWorkspace, propagateWriteKind, setWorkspace } from "./visitNodeUtils";
export function visitTWrapped(state: SerializeParameterState, node: PQP.Language.Ast.TWrapped): void {
const isMultiline: boolean = expectGetIsMultiline(state.isMultilineMap, node);

Просмотреть файл

@ -2,9 +2,10 @@
// Licensed under the MIT license.
import * as PQP from "@microsoft/powerquery-parser";
import { propagateWriteKind, setWorkspace } from "./visitNodeUtils";
import { SerializeParameter, SerializeParameterState, SerializeWriteKind } from "../commonTypes";
import { expectGetIsMultiline } from "../isMultiline/common";
import { propagateWriteKind, setWorkspace } from "./visitNodeUtils";
export function visitTableType(state: SerializeParameterState, node: PQP.Language.Ast.TableType): void {
propagateWriteKind(state, node, node.tableConstant);

Просмотреть файл

@ -2,9 +2,10 @@
// Licensed under the MIT license.
import * as PQP from "@microsoft/powerquery-parser";
import { propagateWriteKind, setWorkspace, skipPrimaryTypeIndentation } from "./visitNodeUtils";
import { SerializeParameter, SerializeParameterState, SerializeWriteKind } from "../commonTypes";
import { expectGetIsMultiline } from "../isMultiline/common";
import { propagateWriteKind, setWorkspace, skipPrimaryTypeIndentation } from "./visitNodeUtils";
export function visitTypePrimaryType(state: SerializeParameterState, node: PQP.Language.Ast.TypePrimaryType): void {
propagateWriteKind(state, node, node.constant);

Просмотреть файл

@ -2,8 +2,9 @@
// Licensed under the MIT license.
import * as PQP from "@microsoft/powerquery-parser";
import { SerializeParameterState, SerializeWriteKind } from "../commonTypes";
import { propagateWriteKind, setWorkspace } from "./visitNodeUtils";
import { SerializeParameterState, SerializeWriteKind } from "../commonTypes";
export function visitUnaryExpression(state: SerializeParameterState, node: PQP.Language.Ast.UnaryExpression): void {
propagateWriteKind(state, node, node.operators);

Просмотреть файл

@ -2,6 +2,7 @@
// Licensed under the MIT license.
import * as PQP from "@microsoft/powerquery-parser";
import {
CommentCollectionMap,
IndentationChange,

Просмотреть файл

@ -1,9 +1,9 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import "mocha";
import * as PQP from "@microsoft/powerquery-parser";
import { expect } from "chai";
import "mocha";
import { FormatSettings, IndentationLiteral, NewlineLiteral, TriedFormat, tryFormat } from "..";