Fix code gen for TSTypeAssertion and TSNonNullExpression
MODIFY
packages/@romejs/js-ast-utils/isTypeExpressionWrapperNode.ts
packages/@romejs/js-ast-utils/isTypeExpressionWrapperNode.ts
* LICENSE file in the root directory of this source tree.
*/
-import {AnyNode, FlowTypeCastExpression, TSAsExpression} from '@romejs/js-ast';
+import {
+ AnyNode,
+ FlowTypeCastExpression,
+ TSAsExpression,
+ TSTypeAssertion,
+ TSNonNullExpression,
+} from '@romejs/js-ast';
export default function isTypeExpressionWrapperNode(
node: AnyNode,
-): node is FlowTypeCastExpression | TSAsExpression {
- return node.type === 'FlowTypeCastExpression' || node.type === 'TSAsExpression';
+): node is
+ | FlowTypeCastExpression
+ | TSAsExpression
+ | TSTypeAssertion
+ | TSNonNullExpression {
+ return (
+ node.type === 'FlowTypeCastExpression' || node.type === 'TSAsExpression' ||
+ node.type === 'TSTypeAssertion' || node.type === 'TSNonNullExpression'
+ );
}

MODIFY
packages/@romejs/js-generator/generators/typescript/TSNonNullExpression.ts
packages/@romejs/js-generator/generators/typescript/TSNonNullExpression.ts
@@ -11,5 +11,7 @@ import {Generator} from '@romejs/js-generator';
export default function TSNonNullExpression(generator: Generator, node: AnyNode) {
node = tsNonNullExpression.assert(node);
generator.print(node.expression, node);
+ if (generator.options.typeAnnotations) {
generator.token('!');
}
+}

MODIFY
packages/@romejs/js-generator/generators/typescript/TSTypeAssertion.ts
packages/@romejs/js-generator/generators/typescript/TSTypeAssertion.ts
@@ -10,9 +10,11 @@ import {Generator} from '@romejs/js-generator';
export default function TSTypeAssertion(generator: Generator, node: AnyNode) {
node = tsTypeAssertion.assert(node);
+ if (generator.options.typeAnnotations) {
generator.token('<');
generator.print(node.typeAnnotation, node);
generator.token('>');
generator.space();
+ }
generator.print(node.expression, node);
}

Fix code gen for TSTypeAssertion and TSNonNullExpression