Skip to content

Print class property definite assignment assertions#1013

Merged
eventualbuddha merged 1 commit into
benjamn:masterfrom
lokshunhung:fix/ts-class-prop-definite
Apr 27, 2022
Merged

Print class property definite assignment assertions#1013
eventualbuddha merged 1 commit into
benjamn:masterfrom
lokshunhung:fix/ts-class-prop-definite

Conversation

@lokshunhung

Copy link
Copy Markdown
Contributor

Resolves #1012

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

@eventualbuddha

Copy link
Copy Markdown
Collaborator

Thanks! Mind adding a test?

@lokshunhung

Copy link
Copy Markdown
Contributor Author

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

@eventualbuddha

Copy link
Copy Markdown
Collaborator

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

Maybe here?

@lokshunhung
lokshunhung force-pushed the fix/ts-class-prop-definite branch from 96cf8d0 to 99c4fb9 Compare December 11, 2021 13:35
@lokshunhung

Copy link
Copy Markdown
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
Copy Markdown
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 force-pushed the fix/ts-class-prop-definite branch from 99c4fb9 to e71ab9b Compare April 27, 2022 22:54
@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