Skip to content
This repository was archived by the owner on Jan 19, 2019. It is now read-only.

Commit 439ea24

Browse files
azzJamesHenry
authored andcommitted
New: Support Definite Assignment (fixes #424) (#432)
1 parent adc0b1b commit 439ea24

File tree

5 files changed

+953
-0
lines changed

5 files changed

+953
-0
lines changed

lib/convert.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,10 @@ module.exports = function convert(config) {
658658
init: convertChild(node.initializer)
659659
});
660660

661+
if (node.exclamationToken) {
662+
result.definite = true;
663+
}
664+
661665
if (node.type) {
662666
result.id.typeAnnotation = convertTypeAnnotation(node.type);
663667
fixTypeAnnotationParentLocation(result.id);
@@ -859,6 +863,10 @@ module.exports = function convert(config) {
859863
result.key.optional = true;
860864
}
861865

866+
if (node.exclamationToken) {
867+
result.definite = true;
868+
}
869+
862870
if (result.key.type === AST_NODE_TYPES.Literal && node.questionToken) {
863871
result.optional = true;
864872
}

tests/ast-alignment/fixtures-to-test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,8 @@ let fixturePatternConfigsToTest = [
349349
"interface-with-all-property-types", // babylon parse errors
350350
"interface-with-construct-signature-with-parameter-accessibility", // babylon parse errors
351351
"class-with-implements-and-extends", // babylon parse errors
352+
"var-with-definite-assignment", // babylon parse errors
353+
"class-with-definite-assignment", // babylon parse errors
352354
/**
353355
* typescript-eslint-parser erroring, but babylon not.
354356
*/
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class X {
2+
a!: string;
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const x!: string;
2+
var y!: number;
3+
let z!: object;

0 commit comments

Comments
 (0)