Skip to content

@link JSDoc annotation cause to fatal error #1058

Description

@Toliak

Description
I have updated TypeScriptToLua from 0.39.3 to the latest, 0.41.0, and received an error:

error TS2304: Cannot find name 'https'

However, I use https only in my JSDoc comment.
I have prepared the simple example to reproduce the error.

Code

/**
 * @see {@link https://toliak.ru/ SomeWebsite }
 */
function helloWorld() {
    return 'Hello World';
}

Also those lines cause to error:

  • * @see a a a a {@link https://toliak.ru/ SomeWebsite }
  • * @asdadasd {@link https://toliak.ru/ SomeWebsite }
  • * @asdadasd a a a {@link https://toliak.ru/ SomeWebsite }

And those lines works fine:

  • * aboba {@link https://toliak.ru/ SomeWebsite }
  • * {@link https://toliak.ru/ SomeWebsite }

I think that is a bug, because I use https in the comment and there is no rules, that prohibit me from using link here.

My environment version info:

NPM version

{
  p_20210801: '1.0.0',
  npm: '6.14.10',
  ares: '1.16.1',
  brotli: '1.0.9',
  cldr: '37.0',
  icu: '67.1',
  llhttp: '2.1.3',
  modules: '83',
  napi: '7',
  nghttp2: '1.41.0',
  node: '14.15.4',
  openssl: '1.1.1i',
  tz: '2020a',
  unicode: '13.0',
  uv: '1.40.0',
  v8: '8.4.371.19-node.17',
  zlib: '1.2.11'
}

NPM Packages

What about tsc
It works correctly

> tsc -b --verbose

[6:34:37 PM] Projects in this build:
    * tsconfig.json

[6:34:37 PM] Project 'tsconfig.json' is out of date because output file 'index.js' does not exist

[6:34:37 PM] Building project 'C:/Users/Toliak/WebstormProjects/p_20210801/tsconfig.json'...

Process finished with exit code 0

Activity

  1. changed the title [-][Bug] @link annotation cause to fatal error[/-] [+][Bug] @link JSDoc annotaion cause to fatal error[/+] on Aug 1, 2021
  2. changed the title [-][Bug] @link JSDoc annotaion cause to fatal error[/-] [+][Bug] @link JSDoc annotation cause to fatal error[/+] on Aug 1, 2021
  3. Toliak commented on Aug 1, 2021

    @Toliak
    ContributorAuthor

    I am debugging the compiling process and here I will put interesting things, that can help

    Stacktrace from point, where diagnostic error is being added

    Stacktrace
    add(), typescript.js:17233
    error(), typescript.js:45782
    resolveNameHelper(), typescript.js:46734
    resolveName(), typescript.js:46386
    resolveEntityName(), typescript.js:47678
    getSymbolOfNameOrPropertyAccessExpression(), typescript.js:80766
    getSymbolAtLocation(), typescript.js:80832
    getSymbolAtLocation(), typescript.js:45218
    buildLinkParts(), typescript.js:120702
    anonymous(), typescript.js:130706
    flatMap(), typescript.js:709
    getDisplayPartsFromComment(), typescript.js:130706
    getCommentDisplayParts(), typescript.js:130730
    anonymous(), typescript.js:130696
    forEachUnique(), typescript.js:120461
    getJsDocTagsFromDeclarations(), typescript.js:130693
    getJsDocTagsOfSignature(), typescript.js:153090
    SignatureObject.getJsDocTags(), typescript.js:153075
    collectAnnotations(), annotations.js:31
    getSignatureAnnotations(), annotations.js:85
    anonymous(), annotations.js:141
    isInTupleReturnFunction(), annotations.js:141
    transformExpressionsInReturn(), return.js:39
    transformReturnStatement(), return.js:83
    transformNode(), context.js:44
    anonymous(), context.js:70
    transformStatements(), context.js:70
    transformFunctionBodyContent(), function.js:37
    transformFunctionBody(), function.js:74
    transformFunctionToExpression(), function.js:135
    transformFunctionDeclaration(), function.js:180
    transformNode(), context.js:44
    anonymous(), context.js:70
    transformStatements(), context.js:70
    transformSourceFileNode(), sourceFile.js:29
    transformNode(), context.js:44
    transformSourceFile(), index.js:28
    processSourceFile(), transpile.js:52
    anonymous(), transformers.js:12
    transformSourceFileOrBundle(), typescript.js:84905
    transformation(), typescript.js:102910
    transformRoot(), typescript.js:102937
    transformNodes(), typescript.js:102921
    emitJsFileOrBundle(), typescript.js:103606
    emitSourceFileOrBundle(), typescript.js:103553
    forEachEmittedFile(), typescript.js:103274
    emitFiles(), typescript.js:103533
    emitWorker(), typescript.js:110329
    anonymous(), typescript.js:110306
    runWithCancellationToken(), typescript.js:110401
    emit(), typescript.js:110306
    getProgramTranspileResult(), transpile.js:90
    emit(), transpiler.js:20
    performCompilation(), tstl.js:84
    executeCommandLine(), tstl.js:60
    anonymous(), tstl.js:157
    Module._compile(), loader.js:1063
    Module._extensions..js(), loader.js:1092
    Module.load(), loader.js:928
    Module._load(), loader.js:769
    executeUserEntryPoint(), run_main.js:72
    anonymous(), run_main_module.js:17
  4. changed the title [-][Bug] @link JSDoc annotation cause to fatal error[/-] [+]@link JSDoc annotation cause to fatal error[/+] on Aug 2, 2021
  5. Perryvw commented on Aug 3, 2021

    @Perryvw
    Member

    I have tried debugging this a bit too, your stack trace seems correct. This actually looks more like a bug in TypeScript. As far as I can see the last thing tstl does is to try to call getJsDocTags() on the helloWorld function (in your example) signature symbol, which then prompts TS to try to resolve https as a variable name for some reason.

    This seems like it should be easily reproducible with the example code you posted here and a small compiler API program that just calls getJsDocTags() on the function's signature symbol, no extra packages required.

    You can open an issue with TypeScript yourself, or if you would like me to do it I can do so somewhere later this week.

  6. added a commit that references this issue on Aug 4, 2021
  7. Toliak commented on Aug 4, 2021

    @Toliak
    ContributorAuthor

    I have tried to reproduce this error with typescript.js, however it works correctly for me

    Code I used
    const ts = require("typescript");
    
    const rootNames = ["C:/Users/Toliak/WebstormProjects/p_20210801/index.ts"]
    const options = {
        target: ts.ScriptTarget.ES5,
        module: ts.ModuleKind.CommonJS
    }
    const projectReferences = undefined
    const configFileParsingDiagnostics = []
    
    const program = ts.createProgram({
        rootNames,
        options,
        projectReferences,
        configFileParsingDiagnostics,
    });
    const sources = program.getSourceFiles()
    const source = sources[5]; // The last
    
    const result = program.emit()
    
    const statement = source.statements[0]
    const tags = statement.symbol.getJsDocTags()
    console.log('tags', tags)
    
    
    const diag = ts.getPreEmitDiagnostics(program)
    
    console.log(result)
    console.log(diag)
    console.log('ok')

    Output:

    > node custom-compile.js
    
    tags [ { name: 'see', text: [ [Object], [Object], [Object], [Object] ] } ]
    {
      emitSkipped: false,
      diagnostics: [],
      emittedFiles: undefined,
      sourceMaps: undefined,
      exportedModulesFromDeclarationEmit: undefined
    }
    []
    ok
    

    Am I doing something wrong while trying to reproduce the error with typescript API calls?

  8. Perryvw commented on Aug 4, 2021

    @Perryvw
    Member

    Amazing job, this is exactly what I had in mind. I think you only need a small tweak to match what TSTL does in this case. On closer inspection it seems the symbol part was a mistake on my part, sorry! I double checked below modification next to the TSTL code:

    Intead of:

    const tags = statement.symbol.getJsDocTags()

    I think tstl does this:

    const type = program.getTypeChecker().getTypeAtLocation(statement);
    const signatures = type.getCallSignatures();
    
    for (const signature of signatures) {
        console.log('tags', signature.getJsDocTags())
    }
  9. Toliak commented on Aug 5, 2021

    @Toliak
    ContributorAuthor

    I have fixed the code snipped, now it looks like:

    New code snipped for testing
    const ts = require("typescript");
    
    const rootNames = ["C:/Users/Toliak/WebstormProjects/p_20210801/index.ts"]
    const options = {
        target: ts.ScriptTarget.ES5,
        module: ts.ModuleKind.CommonJS
    }
    const projectReferences = undefined
    const configFileParsingDiagnostics = []
    
    const program = ts.createProgram({
        rootNames,
        options,
        projectReferences,
        configFileParsingDiagnostics,
    });
    
    const sources = program.getSourceFiles()
    const source = sources[5]; // The last
    
    const result = program.emit()
    
    const statement = source.statements[0]
    
    //
    const type = program.getTypeChecker().getTypeAtLocation(statement);
    const signatures = type.getCallSignatures();
    
    for (const signature of signatures) {
        console.log('tags', signature.getJsDocTags())
    }
    //
    
    const diag = ts.getPreEmitDiagnostics(program)
    console.log(result)
    console.log(diag)
    console.log('ok')

    The output now is:

    tags [ { name: 'see', text: [ [Object], [Object], [Object], [Object] ] } ]
    {
      emitSkipped: false,
      diagnostics: [],
      emittedFiles: undefined,
      sourceMaps: undefined,
      exportedModulesFromDeclarationEmit: undefined
    }
    []
    ok
    

    So, it is still works correctly for pure TypeScript API

  10. Perryvw commented on Aug 5, 2021

    @Perryvw
    Member

    That looks correct and basically how I understand TSTL to work. I will have to debug TSTL some more (I can reproduce this quite easily), maybe some of these variables are not exactly what I expect them to be. I might check in the weekend.

  11. Perryvw commented on Aug 16, 2021

    @Perryvw
    Member

    This will be fixed by #1090 (it deletes the method that is causing the error)

  12. linked a pull request that will close this issueRemove tupleReturn annotation #1090on Aug 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions