Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: benjamn/recast
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.22.0
Choose a base ref
...
head repository: benjamn/recast
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.23.0
Choose a head ref
  • 6 commits
  • 4 files changed
  • 1 contributor

Commits on Dec 10, 2022

  1. Use semicolons in TSTypeLiteral again (not commas though).

    Follow-up to PR #1157 that I caught while trying to regenerate the
    TypeScript declarations for ast-types, and noticed a bunch of (IMHO
    reasonable) semicolons going missing.
    benjamn committed Dec 10, 2022

    Verified

    This commit was signed with the committer’s verified signature.
    benjamn Ben Newman
    Copy the full SHA
    1ac55c8 View commit details
  2. Verified

    This commit was signed with the committer’s verified signature.
    benjamn Ben Newman
    Copy the full SHA
    f76948e View commit details
  3. Verified

    This commit was signed with the committer’s verified signature.
    benjamn Ben Newman
    Copy the full SHA
    808e539 View commit details

Commits on Dec 11, 2022

  1. Revert "Publish prerelease version of PR #1247 to npm."

    This reverts commit 808e539.
    
    I usually bump the main package version on the main/master branch after
    merging PRs, but I wanted the commit I published to npm (git tag
    v0.23.0-pr-1247, recast@0.23.0-pr-1247, npm dist-tag pr-1247) to appear
    in the Git history somewhere, even though this commit reverts it.
    benjamn committed Dec 11, 2022

    Verified

    This commit was signed with the committer’s verified signature.
    benjamn Ben Newman
    Copy the full SHA
    298deac View commit details
  2. Merge pull request #1247 from benjamn/restore-pretty-printing-ts-obje…

    …ct-type-semicolons
    
    Restore pretty-printing TypeScript `type T = {...}` and
    `interface T {...}` semicolons between child members.
    benjamn authored Dec 11, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    56416d1 View commit details
  3. Bump npm version to 0.23.0.

    benjamn committed Dec 11, 2022

    Verified

    This commit was signed with the committer’s verified signature.
    benjamn Ben Newman
    Copy the full SHA
    568e2cd View commit details
Showing with 66 additions and 34 deletions.
  1. +19 −5 lib/printer.ts
  2. +2 −2 package-lock.json
  3. +1 −1 package.json
  4. +44 −26 test/typescript.ts
24 changes: 19 additions & 5 deletions lib/printer.ts
Original file line number Diff line number Diff line change
@@ -930,7 +930,7 @@ function genericPrintNoParens(path: any, options: any, print: any) {

case "StringLiteral":
return fromString(nodeStr(n.value, options));

case "BooleanLiteral": // Babel 6 Literal split
case "Literal":
return fromString(
@@ -2194,13 +2194,20 @@ function genericPrintNoParens(path: any, options: any, print: any) {
]);

case "TSTypeLiteral": {
const memberLines = fromString("\n").join(path.map(print, "members"));
const members = fromString("\n").join(
path.map(print, "members").map((member: Lines) => {
if (lastNonSpaceCharacter(member) !== ";") {
return member.concat(";");
}
return member;
})
);

if (memberLines.isEmpty()) {
if (members.isEmpty()) {
return fromString("{}", options);
}

parts.push("{\n", memberLines.indent(options.tabWidth), "\n}");
parts.push("{\n", members.indent(options.tabWidth), "\n}");

return concat(parts);
}
@@ -2421,7 +2428,14 @@ function genericPrintNoParens(path: any, options: any, print: any) {
]);

case "TSInterfaceBody": {
const lines = fromString("\n").join(path.map(print, "body"));
const lines = fromString("\n").join(
path.map(print, "body").map((element: Lines) => {
if (lastNonSpaceCharacter(element) !== ";") {
return element.concat(";");
}
return element;
})
);
if (lines.isEmpty()) {
return fromString("{}", options);
}
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"author": "Ben Newman <bn@cs.stanford.edu>",
"name": "recast",
"version": "0.22.0",
"version": "0.23.0",
"description": "JavaScript syntax tree transformer, nondestructive pretty-printer, and automatic source map generator",
"keywords": [
"ast",
70 changes: 44 additions & 26 deletions test/typescript.ts
Original file line number Diff line number Diff line change
@@ -44,8 +44,8 @@ const nodeMajorVersion = parseInt(process.versions.node, 10);
"type I = intrinsic;",
"",
"type J = {",
" a: string",
" b?: number",
" a: string;",
" b?: number;",
"};",
]);

@@ -60,19 +60,19 @@ const nodeMajorVersion = parseInt(process.versions.node, 10);

check([
"type A<T, U> = {",
' u: "cat"',
" x: number",
" y: T",
" z: U",
' u: "cat";',
" x: number;",
" y: T;",
" z: U;",
"};",
]);

check([
"type F = <T, U>(",
" a: string,",
" b: {",
" y: T",
" z: U",
" y: T;",
" z: U;",
" }",
") => void;",
]);
@@ -131,7 +131,7 @@ const nodeMajorVersion = parseInt(process.versions.node, 10);
"",
"function create<T>(",
" c: {",
" new<U>(a: U): T",
" new<U>(a: U): T;",
" }",
"): void {}",
]);
@@ -213,23 +213,23 @@ const nodeMajorVersion = parseInt(process.versions.node, 10);

check([
"interface LabelledContainer<T> {",
" label: string",
" content: T",
" option?: boolean",
" readonly x: number",
" [index: number]: string",
" [propName: string]: any",
" readonly [index: number]: string",
" (source: string, subString: string): boolean",
" (start: number): string",
" reset(): void",
" a(c: (this: void, e: E) => void): void",
" label: string;",
" content: T;",
" option?: boolean;",
" readonly x: number;",
" [index: number]: string;",
" [propName: string]: any;",
" readonly [index: number]: string;",
" (source: string, subString: string): boolean;",
" (start: number): string;",
" reset(): void;",
" a(c: (this: void, e: E) => void): void;",
"}",
]);

check([
"interface Square<T, U> extends Shape<T, U>, Visible<T, U> {",
" sideLength: number",
" sideLength: number;",
"}",
]);

@@ -265,19 +265,31 @@ const nodeMajorVersion = parseInt(process.versions.node, 10);
"}",
])

check(["export interface S {", " i(s: string): boolean", "}"]);
check([
"export interface S {",
" i(s: string): boolean;",
"}"
]);

check([
"namespace Validation {",
" export interface S {",
" i(j: string): boolean",
" i(j: string): boolean;",
" }",
"}",
]);

check(["export interface S {", " i(j: string): boolean", "}"]);
check([
"export interface S {",
" i(j: string): boolean;",
"}",
]);

check(["declare namespace D3 {", " export const f: number;", "}"]);
check([
"declare namespace D3 {",
" export const f: number;",
"}",
]);

check(["declare function foo<K, V>(arg: T = getDefault()): R"]);

@@ -287,7 +299,13 @@ const nodeMajorVersion = parseInt(process.versions.node, 10);
"}",
]);

check(["function myFunction(", " {", " param1", " }: Params", ") {}"]);
check([
"function myFunction(",
" {",
" param1",
" }: Params",
") {}",
]);

check([
'const unqualified: import("package") = 1;',