Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/next' into arthur/oclif
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurfiorette committed May 29, 2024
2 parents a6e0eb6 + 2880903 commit aa994ce
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 117 deletions.
5 changes: 3 additions & 2 deletions eslint.config.js → eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import eslintPluginPrettierRecommended from "eslint-plugin-prettier/recommended"
/** @type {import('@types/eslint').Linter.FlatConfig[]} */
export default tseslint.config(
{
ignores: ["dist", "cjs", "build"],
ignores: ["dist", "cjs", "build", "eslint.config.mjs"],
},
eslint.configs.recommended,
{
files: ["index.ts", "src/**/*.ts", "factory/**/*.ts", "bin/**", "test/**/*.test.ts", "test/utils.ts"],
extends: tseslint.configs.recommendedTypeChecked,
languageOptions: {
sourceType: "module",
sourceType: "commonjs",
parserOptions: {
project: "tsconfig.eslint.json",
tsconfigRootDir: import.meta.dirname,
Expand Down Expand Up @@ -63,6 +63,7 @@ export default tseslint.config(
languageOptions: {
globals: {
...globals.jest,
...globals.commonjs,
},
},
},
Expand Down
13 changes: 5 additions & 8 deletions src/NodeParser/FunctionNodeParser.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import ts from "typescript";
import { SubNodeParser } from "../SubNodeParser.js";
import { BaseType } from "../Type/BaseType.js";
import type { SubNodeParser } from "../SubNodeParser.js";
import type { BaseType } from "../Type/BaseType.js";
import { FunctionType } from "../Type/FunctionType.js";
import { FunctionOptions } from "../Config.js";
import type { FunctionOptions } from "../Config.js";
import { NeverType } from "../Type/NeverType.js";
import { DefinitionType } from "../Type/DefinitionType.js";
import { Context, NodeParser } from "../NodeParser.js";
import type { Context, NodeParser } from "../NodeParser.js";
import { ObjectProperty, ObjectType } from "../Type/ObjectType.js";
import { getKey } from "../Utils/nodeKey.js";

Expand All @@ -15,14 +15,11 @@ export class FunctionNodeParser implements SubNodeParser {
protected functions: FunctionOptions,
) {}

public supportsNode(node: ts.TypeNode): boolean {
public supportsNode(node: ts.Node): boolean {
return (
node.kind === ts.SyntaxKind.FunctionType ||
// @ts-expect-error internals type bug
node.kind === ts.SyntaxKind.FunctionExpression ||
// @ts-expect-error internals type bug
node.kind === ts.SyntaxKind.ArrowFunction ||
// @ts-expect-error internals type bug
node.kind === ts.SyntaxKind.FunctionDeclaration
);
}
Expand Down
4 changes: 3 additions & 1 deletion src/NodeParser/PromiseNodeParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export class PromiseNodeParser implements SubNodeParser {

const type = this.typeChecker.getTypeAtLocation(node);

//@ts-expect-error - internal typescript API
const awaitedType = this.typeChecker.getAwaitedType(type);

// ignores non awaitable types
Expand Down Expand Up @@ -60,7 +61,8 @@ export class PromiseNodeParser implements SubNodeParser {
context: Context,
): BaseType {
const type = this.typeChecker.getTypeAtLocation(node);
const awaitedType = this.typeChecker.getAwaitedType(type)!; // supportsNode ensures this
//@ts-expect-error - internal typescript API
const awaitedType = this.typeChecker.getAwaitedType(type);
const awaitedNode = this.typeChecker.typeToTypeNode(awaitedType, undefined, ts.NodeBuilderFlags.IgnoreErrors);

if (!awaitedNode) {
Expand Down
3 changes: 2 additions & 1 deletion src/NodeParser/TypeReferenceNodeParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { AnyType } from "../Type/AnyType.js";
import { ArrayType } from "../Type/ArrayType.js";
import type { BaseType } from "../Type/BaseType.js";
import { StringType } from "../Type/StringType.js";
import { symbolAtNode } from "../Utils/symbolAtNode.js";

const invalidTypes: Record<number, boolean> = {
[ts.SyntaxKind.ModuleDeclaration]: true,
Expand All @@ -28,7 +29,7 @@ export class TypeReferenceNodeParser implements SubNodeParser {
// When the node doesn't have a valid source file, its position is -1, so we can't
// search for a symbol based on its location. In that case, the ts.factory defines a symbol
// property on the node itself.
(node.typeName as unknown as ts.Type).symbol;
symbolAtNode(node.typeName)!;

if (typeSymbol.flags & ts.SymbolFlags.Alias) {
const aliasedSymbol = this.typeChecker.getAliasedSymbol(typeSymbol);
Expand Down
4 changes: 3 additions & 1 deletion src/SchemaGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type { TypeFormatter } from "./TypeFormatter.js";
import type { StringMap } from "./Utils/StringMap.js";
import { hasJsDocTag } from "./Utils/hasJsDocTag.js";
import { removeUnreachable } from "./Utils/removeUnreachable.js";
import { symbolAtNode } from "./Utils/symbolAtNode.js";

export class SchemaGenerator {
public constructor(
Expand Down Expand Up @@ -262,6 +263,7 @@ export class SchemaGenerator {
return false;
}

//@ts-expect-error - internal typescript API
return !!node.localSymbol?.exportSymbol;
}

Expand All @@ -270,6 +272,6 @@ export class SchemaGenerator {
}

protected getFullName(node: ts.Declaration, typeChecker: ts.TypeChecker): string {
return typeChecker.getFullyQualifiedName(node.symbol).replace(/".*"\./, "");
return typeChecker.getFullyQualifiedName(symbolAtNode(node)!).replace(/".*"\./, "");
}
}
3 changes: 2 additions & 1 deletion src/Utils/symbolAtNode.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type ts from "typescript";

export function symbolAtNode(node: ts.Node): ts.Symbol | undefined {
return (node as ts.Declaration).symbol;
//@ts-expect-error - internal typescript API
return node.symbol;
}
12 changes: 0 additions & 12 deletions tsconfig.cjs.json

This file was deleted.

4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"compilerOptions": {
"target": "ES2022",
"module": "NodeNext",
"moduleResolution": "Node16",
"module": "CommonJS",
"moduleResolution": "Node",
"esModuleInterop": true,
"isolatedModules": false,
"experimentalDecorators": true,
Expand Down
Loading

0 comments on commit aa994ce

Please sign in to comment.