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

Print class property definite assignment assertions #1013

Merged

Conversation

lokshunhung
Copy link
Contributor

Resolves #1012

This PR makes the printer aware of definite property in ClassProperty AST node, printing ! when true

@eventualbuddha
Copy link
Collaborator

Thanks! Mind adding a test?

@lokshunhung
Copy link
Contributor Author

@eventualbuddha Sure, could you point me to the location where I should put this?

@eventualbuddha
Copy link
Collaborator

@eventualbuddha Sure, could you point me to the location where I should put this?

Maybe here?

@lokshunhung
Copy link
Contributor Author

@eventualbuddha I checked test/typescript.ts and it seems that it contains tests for checking syntax validity and reprinting

I put the tests inside test/printer.ts below this

@lokshunhung
Copy link
Contributor Author

I had to use Object.assign(b.classProperty(...), { definite: true }) instead of b.classProperty.from(...) in the test, as it seems that ast-types does not handle the definite property in ClassProperty nodes 😅

import * as assert from "assert";
import * as ast from "ast-types";

const b = ast.builders;

const n1 = Object.assign(
  b.classProperty(
    b.identifier("key"),
    null
  ),
  { definite: true }
);

const n2 = b.classProperty.from({
  key: b.identifier("key"),
  value: null,
  definite: true,
});

assert.deepStrictEqual(n1, n2);
Expected values to be strictly deep-equal: 
+ actual - expected ... Lines skipped 
 
  { 
    access: undefined, 
    comments: null, 
    computed: false, 
+   definite: true, 
    key: { 
... 
    value: null, 
    variance: null 
  }

@eventualbuddha eventualbuddha merged commit 06eca93 into benjamn:master Apr 27, 2022
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

Successfully merging this pull request may close these issues.

Cannot add typescript definite assignment assertions to class properties
2 participants