cevek / ttypescript

Over TypeScript tool to use custom transformers in the tsconfig.json
1.53k stars 56 forks source link

Transforming Typescript aliases returns "Debug Failure. False expression: Node must have a real position for this operation" #108

Closed yankeeinlondon closed 3 years ago

yankeeinlondon commented 3 years ago

I have code which compiles without issue using tsc but when used with ttsc or Rollup with the ttypscript replacement. My tsconfig.json file is:

{
  "compilerOptions": {
    "declaration": false,
    "module": "esnext",
    "target": "es2018",
    "lib": ["es2015.reflect", "DOM"],
    "moduleResolution": "node",
    "sourceMap": true,
    "noImplicitAny": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "noEmit": true,
    "removeComments": false,
    "strictNullChecks": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "baseUrl": ".",
    "paths": {
      "@/*": ["src/*"]
    },
    "plugins": [
      { "transform": "typescript-transform-paths" },
      { "transform": "typescript-transform-paths", "afterDeclarations": true }
    ]
  },

  "include": ["src"]
}

This same repo and tsconfig used to compile but after updating a number of requirements (including Typescript to 4.1.3) it now fails with:

Error: Debug Failure. False expression: Node must have a real position for this operation
    at NodeObject.assertHasRealPosition (/Volumes/Coding/forest-fire/vuex-plugin-firemodel/node_modules/typescript/lib/typescript.js:146074:22)
    at NodeObject.getFullText (/Volumes/Coding/forest-fire/vuex-plugin-firemodel/node_modules/typescript/lib/typescript.js:146104:18)
    at getStatementTags (/Volumes/Coding/forest-fire/vuex-plugin-firemodel/node_modules/typescript-transform-paths/dist/utils/resolve-path-update-node.js:96:35)
    at Object.resolvePathAndUpdateNode (/Volumes/Coding/forest-fire/vuex-plugin-firemodel/node_modules/typescript-transform-paths/dist/utils/resolve-path-update-node.js:17:18)
    at Object.nodeVisitor (/Volumes/Coding/forest-fire/vuex-plugin-firemodel/node_modules/typescript-transform-paths/dist/visitor.js:76:24)
    at visitNodes (/Volumes/Coding/forest-fire/vuex-plugin-firemodel/node_modules/typescript/lib/typescript.js:80382:48)

I have gone into Typescript's code and added code to pull out more information as I was completely confused by the message. When I hit an error condition, I now get a dump of the node's context which looks like this:

NodeObject {
  pos: -1,
  end: -1,
  flags: 8,
  modifierFlagsCache: 0,
  transformFlags: 1,
  parent: undefined,
  kind: 195,
  argument: NodeObject {
    pos: -1,
    end: -1,
    flags: 8,
    modifierFlagsCache: 0,
    transformFlags: 1,
    parent: undefined,
    kind: 191,
    literal: TokenObject {
      pos: -1,
      end: -1,
      flags: 8,
      modifierFlagsCache: 0,
      transformFlags: 0,
      parent: undefined,
      kind: 10,
      text: '@firebase/auth-types',
      singleQuote: undefined,
      hasExtendedUnicodeEscape: undefined
    }
  },
  qualifier: IdentifierObject {
    pos: -1,
    end: -1,
    flags: 8,
    modifierFlagsCache: 0,
    transformFlags: 0,
    parent: undefined,
    kind: 78,
    originalKeywordKind: undefined,
    escapedText: 'FirebaseAuth',
    emitNode: { flags: 16777216 },
    symbol: SymbolObject {
      flags: 32,
      escapedName: 'FirebaseAuth',
      declarations: [Array],
      exports: [Map],
      members: [Map],
      valueDeclaration: [NodeObject],
      parent: [SymbolObject],
      id: 24262,
      isReferenced: 788968
    },
    typeArguments: undefined
  },
  typeArguments: undefined,
  isTypeOf: false,
  jsDocCache: []
}

With my someone low resolution understanding this seems to suggest it's taking some issue with the FirebaseAuth symbol which is being imported from a package that does indeed export the given symbol. What i've noticed, however, is that if I use the newer import type { symbol } from 'xyz'; this is where it seems to fall over.

Note: my local repo version of typescript and the globally installed version are 4.1.2 (aka, both should support this language feature)

yankeeinlondon commented 3 years ago

Previously

"plugins": [
      { "transform": "typescript-transform-paths" }
      { "transform": "typescript-transform-paths", "afterDeclarations": true }
    ]

Adjusted

"plugins": [
      { "transform": "typescript-transform-paths" }
    ]

I have looked out the output of both the code and the types and it would appear that the path aliases have been transformed which is odd because I know that you needed both transforms to have this effect in the past. Has something changed? I can see now that if I comment out the afterDeclarations transformation (leaving just the default transform), it transpiles.

yankeeinlondon commented 3 years ago

No, i take it back ... there are still path aliases in the type definitions. For instance:

import { AbcApi } from "@/abc";
export declare function getFromVuex<T>(ctx: AbcApi<T>): Promise<any>;
yankeeinlondon commented 3 years ago

This project is open source and this experience can be easily reproduced by cloning: https://github.com/forest-fire/vuex-plugin-firemodel and using the @develop branch.

nonara commented 3 years ago

@ksnyde I suggest filing an issue on the typescript-tranform-paths repo. It is doubtful that this is an issue with ttypescript.

Please include the version number and steps to repro, and I'll have a look when I can.

yankeeinlondon commented 3 years ago

yes I think you're right ... i hacked typescript's code to force my repo to build but I need a more graceful means. It seems more likely that it's in typescript-transform-paths though and not the infrastructure that you're providing. Thanks for the quick return.