Skip to content
New issue

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

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

Already on GitHub? # to your account

[bug] JSII Compilation error for Class Decorator #33213

Closed
wants to merge 2 commits into from

Conversation

pcheungamz
Copy link

Reason for this change

A simple way to demo the JSII Compilation error:

TypeError: Cannot read properties of undefined (reading 'flags')
    at symbolIdentifier (/local/home/cheungp/cdk-jsii-error/aws-cdk/node_modules/jsii/lib/common/symbol-id.js:40:17)
    at Transformer.getStatementsForDeclaration (/local/home/cheungp/cdk-jsii-error/aws-cdk/node_modules/jsii/lib/transforms/deprecation-warnings.js:278:64)
    at Transformer.visitor (/local/home/cheungp/cdk-jsii-error/aws-cdk/node_modules/jsii/lib/transforms/deprecation-warnings.js:266:37)
    at visitArrayWorker (/local/home/cheungp/cdk-jsii-error/aws-cdk/node_modules/jsii/node_modules/typescript/lib/typescript.js:93680:49)
    at visitNodes2 (/local/home/cheungp/cdk-jsii-error/aws-cdk/node_modules/jsii/node_modules/typescript/lib/typescript.js:93651:19)
    at visitEachChildOfClassExpression (/local/home/cheungp/cdk-jsii-error/aws-cdk/node_modules/jsii/node_modules/typescript/lib/typescript.js:94392:7)
    at Object.visitEachChild (/local/home/cheungp/cdk-jsii-error/aws-cdk/node_modules/jsii/node_modules/typescript/lib/typescript.js:93866:33)
    at Transformer.visitEachChild (/local/home/cheungp/cdk-jsii-error/aws-cdk/node_modules/jsii/lib/transforms/deprecation-warnings.js:238:19)
    at Transformer.visitor (/local/home/cheungp/cdk-jsii-error/aws-cdk/node_modules/jsii/lib/transforms/deprecation-warnings.js:270:21)
    at visitNode (/local/home/cheungp/cdk-jsii-error/aws-cdk/node_modules/jsii/node_modules/typescript/lib/typescript.js:93618:19)

Description of changes

New file containing Class Decorator.

Describe any new or updated permissions being added

None

Description of how you validated changes

yarn build in package/aws-cdk-lib produces JSII error.

Checklist


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@pcheungamz pcheungamz requested a review from a team as a code owner January 28, 2025 18:33
@github-actions github-actions bot added the beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK label Jan 28, 2025
@aws-cdk-automation aws-cdk-automation requested a review from a team January 28, 2025 18:33
@github-actions github-actions bot added the p2 label Jan 28, 2025
Copy link
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pull request linter fails with the following errors:

❌ The title prefix of this pull request must be one of "feat|fix|build|chore|ci|docs|style|refactor|perf|test|revert"

If you believe this pull request should receive an exemption, please comment and provide a justification. A comment requesting an exemption should contain the text Exemption Request. Additionally, if clarification is needed, add Clarification Request to a comment.

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: 93d76f4
  • Result: FAILED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@aws-cdk-automation
Copy link
Collaborator

This PR has been in the CHANGES REQUESTED state for 3 weeks, and looks abandoned. Note that PRs with failing linting check or builds are not reviewed, please ensure your build is passing

To prevent automatic closure:

  • Resume work on the PR
  • OR request an exemption by adding a comment containing 'Exemption Request' with justification e.x "Exemption Request: "
  • OR request clarification by adding a comment containing 'Clarification Request' with a question e.x "Clarification Request: "

This PR will automatically close in 7 days if no action is taken.

@mrgrain mrgrain added the pr-linter/do-not-close The PR linter will not close this PR while this label is present label Feb 19, 2025
@mrgrain mrgrain marked this pull request as draft February 19, 2025 10:04
@jiayiwang7 jiayiwang7 added bug This issue is a bug. p1 and removed p2 labels Feb 26, 2025
@jiayiwang7 jiayiwang7 assigned rix0rrr and unassigned rix0rrr Feb 27, 2025
github-merge-queue bot pushed a commit to aws/jsii-compiler that referenced this pull request Mar 5, 2025
`jsii` used to fail when trying to generate deprecation warnings and
given a statement like this:

```ts
export function propertyInjectionDecorator<T extends Constructor>(ctr: T) {
  // Important for the bug: the anonymous class extends something, *and*
  // declares a method.
  return class extends ctr {
    public someMethod(): string {
      return 'abc';
    }
  };
}
```

The reason is that during generation of deprecation warnings we iterate
over all classes and methods (both exported and unexported), and
generate a symbol identifier for every method; but this class is
anonymous
so it doesn't have a symbol, and generating the identifier fails with
the error:

```
TypeError: Cannot read properties of undefined (reading 'flags')
    at symbolIdentifier (.../jsii/lib/common/symbol-id.js:40:17)
```

Handle this by handling the case where we don't have a symbol
and returning `undefined`.

Fixes aws/aws-cdk#33213

---

By submitting this pull request, I confirm that my contribution is made
under the terms of the [Apache 2.0 license].

[Apache 2.0 license]: https://www.apache.org/licenses/LICENSE-2.0

---------

Co-authored-by: Eli Polonsky <Eli.polonsky@gmail.com>
Copy link

github-actions bot commented Mar 5, 2025

Comments on closed issues and PRs are hard for our team to see.
If you need help, please open a new issue that references this one.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 5, 2025
aws-cdk-automation pushed a commit to aws/jsii-compiler that referenced this pull request Mar 10, 2025
`jsii` used to fail when trying to generate deprecation warnings and
given a statement like this:

```ts
export function propertyInjectionDecorator<T extends Constructor>(ctr: T) {
  // Important for the bug: the anonymous class extends something, *and*
  // declares a method.
  return class extends ctr {
    public someMethod(): string {
      return 'abc';
    }
  };
}
```

The reason is that during generation of deprecation warnings we iterate
over all classes and methods (both exported and unexported), and
generate a symbol identifier for every method; but this class is
anonymous
so it doesn't have a symbol, and generating the identifier fails with
the error:

```
TypeError: Cannot read properties of undefined (reading 'flags')
    at symbolIdentifier (.../jsii/lib/common/symbol-id.js:40:17)
```

Handle this by handling the case where we don't have a symbol
and returning `undefined`.

Fixes aws/aws-cdk#33213

---

By submitting this pull request, I confirm that my contribution is made
under the terms of the [Apache 2.0 license].

[Apache 2.0 license]: https://www.apache.org/licenses/LICENSE-2.0

---------

Co-authored-by: Eli Polonsky <Eli.polonsky@gmail.com>
(cherry picked from commit dbd4506)
aws-cdk-automation pushed a commit to aws/jsii-compiler that referenced this pull request Mar 10, 2025
`jsii` used to fail when trying to generate deprecation warnings and
given a statement like this:

```ts
export function propertyInjectionDecorator<T extends Constructor>(ctr: T) {
  // Important for the bug: the anonymous class extends something, *and*
  // declares a method.
  return class extends ctr {
    public someMethod(): string {
      return 'abc';
    }
  };
}
```

The reason is that during generation of deprecation warnings we iterate
over all classes and methods (both exported and unexported), and
generate a symbol identifier for every method; but this class is
anonymous
so it doesn't have a symbol, and generating the identifier fails with
the error:

```
TypeError: Cannot read properties of undefined (reading 'flags')
    at symbolIdentifier (.../jsii/lib/common/symbol-id.js:40:17)
```

Handle this by handling the case where we don't have a symbol
and returning `undefined`.

Fixes aws/aws-cdk#33213

---

By submitting this pull request, I confirm that my contribution is made
under the terms of the [Apache 2.0 license].

[Apache 2.0 license]: https://www.apache.org/licenses/LICENSE-2.0

---------

Co-authored-by: Eli Polonsky <Eli.polonsky@gmail.com>
(cherry picked from commit dbd4506)
aws-cdk-automation pushed a commit to aws/jsii-compiler that referenced this pull request Mar 10, 2025
`jsii` used to fail when trying to generate deprecation warnings and
given a statement like this:

```ts
export function propertyInjectionDecorator<T extends Constructor>(ctr: T) {
  // Important for the bug: the anonymous class extends something, *and*
  // declares a method.
  return class extends ctr {
    public someMethod(): string {
      return 'abc';
    }
  };
}
```

The reason is that during generation of deprecation warnings we iterate
over all classes and methods (both exported and unexported), and
generate a symbol identifier for every method; but this class is
anonymous
so it doesn't have a symbol, and generating the identifier fails with
the error:

```
TypeError: Cannot read properties of undefined (reading 'flags')
    at symbolIdentifier (.../jsii/lib/common/symbol-id.js:40:17)
```

Handle this by handling the case where we don't have a symbol
and returning `undefined`.

Fixes aws/aws-cdk#33213

---

By submitting this pull request, I confirm that my contribution is made
under the terms of the [Apache 2.0 license].

[Apache 2.0 license]: https://www.apache.org/licenses/LICENSE-2.0

---------

Co-authored-by: Eli Polonsky <Eli.polonsky@gmail.com>
(cherry picked from commit dbd4506)
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK bug This issue is a bug. p1 pr-linter/do-not-close The PR linter will not close this PR while this label is present
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants