ts-blank-space
Advanced tools
Comparing version 0.4.2 to 0.4.3
@@ -231,3 +231,3 @@ // Copyright 2024 Bloomberg Finance L.P. | ||
} | ||
visitModifiers(node.modifiers); | ||
visitModifiers(node.modifiers, /* addSemi:*/ false); | ||
} | ||
@@ -284,3 +284,3 @@ | ||
function visitModifiers(modifiers ) { | ||
function visitModifiers(modifiers , addSemi ) { | ||
for (let i = 0; i < modifiers.length; i++) { | ||
@@ -290,3 +290,8 @@ const modifier = modifiers[i]; | ||
if (isRemovedModifier(kind)) { | ||
blankExact(modifier); | ||
if (addSemi && i === 0) { | ||
str.blankButStartWithSemi(modifier.getStart(ast), modifier.end); | ||
addSemi = false; | ||
} else { | ||
blankExact(modifier); | ||
} | ||
continue; | ||
@@ -334,3 +339,3 @@ } else if (kind === SK.Decorator) { | ||
} | ||
visitModifiers(node.modifiers); | ||
visitModifiers(node.modifiers, /* addSemi */ node.name.kind === SK.ComputedPropertyName); | ||
} | ||
@@ -401,8 +406,9 @@ node.exclamationToken && blankExact(node.exclamationToken); | ||
const nodeName = node.name; | ||
if (node.modifiers) { | ||
visitModifiers(node.modifiers); | ||
visitModifiers(node.modifiers, /* addSemi */ !!nodeName && nodeName.kind === SK.ComputedPropertyName); | ||
} | ||
if (node.name) { | ||
visitor(node.name); | ||
if (nodeName) { | ||
visitor(nodeName); | ||
} | ||
@@ -409,0 +415,0 @@ |
{ | ||
"name": "ts-blank-space", | ||
"description": "A small, fast, pure JavaScript type-stripper that uses the official TypeScript parser.", | ||
"version": "0.4.2", | ||
"version": "0.4.3", | ||
"license": "Apache-2.0", | ||
@@ -6,0 +6,0 @@ "homepage": "https://bloomberg.github.io/ts-blank-space", |
@@ -142,5 +142,5 @@ <a href="https://bloomberg.github.io/ts-blank-space"> | ||
To guard against [ASI](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#automatic_semicolon_insertion) issues in the output, `ts-blank-space` will add `;` to the end of type-only statements. | ||
To guard against [ASI](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#automatic_semicolon_insertion) issues in the output, `ts-blank-space` will add `;` to the end of type-only statements, and when removing a leading type annotation could introduce an ASI hazard. | ||
Example input: | ||
#### Example one - type-only statement | ||
@@ -163,2 +163,22 @@ <!-- prettier-ignore --> | ||
#### Example two - computed class fields/methods | ||
<!-- prettier-ignore --> | ||
```typescript | ||
class C { | ||
field = 1/* no ; */ | ||
public ["computed field not accessing above"] = 2 | ||
} | ||
``` | ||
becomes: | ||
<!-- prettier-ignore --> | ||
```javascript | ||
class C { | ||
field = 1/* no ; */ | ||
; ["computed field not accessing above"] = 2 | ||
} | ||
``` | ||
### Arrow function type annotations that introduce a new line | ||
@@ -165,0 +185,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
47531
692
293