Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

type properties are not parsed #123

Open
d9k opened this issue Dec 6, 2023 · 1 comment
Open

type properties are not parsed #123

d9k opened this issue Dec 6, 2023 · 1 comment

Comments

@d9k
Copy link

d9k commented Dec 6, 2023

script

import { TypescriptParser } from 'typescript-parser';

const json = (data: any): string => JSON.stringify(data, null, '  ');

async function main() {
    const timerToPreventFreeze = setTimeout(() => {}, 999999);
    const parser = new TypescriptParser();
    console.log('# interface');
    console.log();
    console.log(json(await parser.parseSource(`
        interface A {
            n: number;
            s: string;
        }
    `)));
    console.log();
    console.log('# type');
    console.log();
    console.log(json(await parser.parseSource(`
        type A = {
            n: number;
            s: string;
        }
    `)));
    clearTimeout(timerToPreventFreeze);
  }

  main().then(() => {
    process.exit()
  });

Result

# interface

{
  "filePath": "inline.tsx",
  "rootPath": "/",
  "start": 9,
  "end": 83,
  "imports": [],
  "exports": [],
  "declarations": [
    {
      "name": "A",
      "isExported": false,
      "start": 9,
      "end": 78,
      "accessors": [],
      "properties": [
        {
          "name": "n",
          "visibility": 2,
          "type": "number",
          "isOptional": false,
          "isStatic": false,
          "start": 35,
          "end": 45
        },
        {
          "name": "s",
          "visibility": 2,
          "type": "string",
          "isOptional": false,
          "isStatic": false,
          "start": 58,
          "end": 68
        }
      ],
      "methods": []
    }
  ],
  "resources": [],
  "usages": [
    "n",
    "s"
  ]
}

# type

{
  "filePath": "inline.tsx",
  "rootPath": "/",
  "start": 9,
  "end": 80,
  "imports": [],
  "exports": [],
  "declarations": [
    {
      "name": "A",
      "isExported": false,
      "start": 9,
      "end": 75
    }
  ],
  "resources": [],
  "usages": [
    "n",
    "s"
  ]
}

@d9k
Copy link
Author

d9k commented Dec 6, 2023

Also no nested type declarations supported

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant