Skip to content

--allowJs: Cannot update prototype of imported class (3.7.0 regression) #34493

Closed

Description

TypeScript Version: 3.7.0-dev.20191015

Code
Initial source:
lodash-es/lodash.default.js file from lodash-es@4.17.15

Minimum repro:

import A from 'A';
A.prototype.foo = 0;

Expected behavior:
Code transpiles without errors

Actual behavior:

node_modules\typescript\lib\tsc.js:23676
            node.symbol = symbol;

    TypeError: node_modules\lodash-es\lodash.default.js: Cannot set property 'symbol' of undefined

      at addDeclarationToSymbol (node_modules/typescript/lib/typescript.js:29235:25)
      at bindPotentiallyMissingNamespaces (node_modules/typescript/lib/typescript.js:31604:17)
      at bindPropertyAssignment (node_modules/typescript/lib/typescript.js:31656:31)
      at bindPrototypePropertyAssignment (node_modules/typescript/lib/typescript.js:31544:13)
      at bindWorker (node_modules/typescript/lib/typescript.js:31139:29)
      at bind (node_modules/typescript/lib/typescript.js:31027:13)
      at bindExpressionStatement (node_modules/typescript/lib/typescript.js:30235:13)
      at bindChildrenWorker (node_modules/typescript/lib/typescript.js:29693:21)
      at bindChildren (node_modules/typescript/lib/typescript.js:29614:17)
      at bind (node_modules/typescript/lib/typescript.js:31038:21)

Playground Link:
http://www.typescriptlang.org/play/?target=1&ts=3.7-Beta&useJavaScript=true#code/JYWwDg9gTgLgBAQTgMyhEcDkDMG4BQCAdGGjBDAJ5gCmRyEEcAvHAAy5A (see error in browser console)

Activity

  1. Knagis commented on Oct 15, 2019

    @Knagis
    ContributorAuthor

    Minimum repro:

    import A from 'A';
    A.prototype.foo = 0;
  2. changed the title [-]Cannot set property 'symbol' of undefined: 3.7.0 cannot transpile lodash-es/lodash.defaults.js[/-] [+]--allowJs: Cannot update prototype of imported class (3.7.0)[/+] on Oct 15, 2019
  3. changed the title [-]--allowJs: Cannot update prototype of imported class (3.7.0)[/-] [+]--allowJs: Cannot update prototype of imported class (3.7.0 regression)[/+] on Oct 16, 2019
  4. sandersn commented on Oct 18, 2019

    @sandersn
    Member

    A is an alias symbol, which doesn't get a valueDeclaration, but the expando binding assumes that the original symbol has a valueDeclaration.

    I'm not sure whether the right fix is to not skip expando binding when the original symbol doesn't have a valueDeclaration, or to rebind the alias' declaration as a valueDeclaration. I'll try both and see which behaves better.

  5. sandersn commented on Oct 18, 2019

    @sandersn
    Member

    Since the RC snaps at 2 PM today, I'm going to fix the crash (option 1 above) and investigate the follow-on crash from option 2 afterward. Option 2 should restore the pre-3.7 behaviour when it works.

  6. sandersn commented on Oct 18, 2019

    @sandersn
    Member

    My historical repro was set up wrong -- now that I've fixed it, I can see that this never worked, so I will probably leave it at fixing the crash.

  7. added a commit that references this issue on Oct 18, 2019
    c2b1170
  8. added a commit that references this issue on Oct 18, 2019
    fa1884e
  9. locked as resolved and limited conversation to collaborators on Oct 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions