ts-blank-space
Advanced tools
Comparing version 0.4.0 to 0.4.1
import { register } from "node:module"; | ||
import { pathToFileURL } from "node:url"; | ||
register("./hooks.js", pathToFileURL(import.meta.filename)); | ||
register("./hooks.js", import.meta.url); |
{ | ||
"name": "ts-blank-space", | ||
"description": "A small, fast, pure JavaScript, type-stripper using the official TypeScript parser", | ||
"version": "0.4.0", | ||
"description": "A small, fast, pure JavaScript type-stripper that uses the official TypeScript parser.", | ||
"version": "0.4.1", | ||
"license": "Apache-2.0", | ||
@@ -6,0 +6,0 @@ "homepage": "https://bloomberg.github.io/ts-blank-space", |
@@ -1,4 +0,6 @@ | ||
<img src="assets/ts-blank-space.png" width="728" alt="'ts-blank-space' as a logo. the 'ts' is in TypeScript blue and the 'blank-space' is in JavaScript orange" /> | ||
<a href="https://bloomberg.github.io/ts-blank-space"> | ||
<img src="assets/ts-blank-space.png" width="728" alt="'ts-blank-space' as a logo. the 'ts' is in TypeScript blue and the 'blank-space' is in JavaScript orange" /> | ||
</a> | ||
A small, fast, pure JavaScript, type-stripper using the official TypeScript parser. | ||
A small, fast, pure JavaScript type-stripper that uses the official TypeScript parser. | ||
@@ -49,4 +51,4 @@ [![npm Badge](https://img.shields.io/npm/v/ts-blank-space.svg)](https://www.npmjs.com/package/ts-blank-space) | ||
- Fastest compared to non-native (JavaScript or Wasm) | ||
- No new JavaScript code is generated, instead it re-uses slices of the existing source string | ||
- This is particularly true if your program is already generating the TypeScript `SourceFile` object because it can [be reused](#bring-your-own-ast), and producing the AST is the most time consuming part. | ||
- No new JavaScript code is generated; instead, it re-uses slices of the existing source string | ||
- This is particularly true if your program is already generating the TypeScript `SourceFile` object, because it can [be reused](#bring-your-own-ast) -- and producing the AST is the most time consuming part. | ||
- 100% JavaScript runtime | ||
@@ -57,8 +59,8 @@ - No [Wasm](https://webassembly.org) | ||
- It is small | ||
- Less than 700 lines of code and one dependency ([`typescript`](https://www.npmjs.com/package/typescript)) | ||
- By doing so little the code should be relatively easy to maintain | ||
- Less than 700 lines of code and one dependency ([`TypeScript`](https://www.npmjs.com/package/typescript)) | ||
- By doing so little, the code should be relatively easy to maintain | ||
- Delegates the parsing to the [official TypeScript parser](https://github.com/microsoft/TypeScript/wiki/Using-the-Compiler-API) | ||
- No need for additional SourceMap processing. See ["where are my SourceMaps?"](#where-are-my-sourcemaps) | ||
- No need for additional SourceMap processing; see ["where are my SourceMaps?"](#where-are-my-sourcemaps) | ||
:information_source: Not all TypeScript syntax is supported (see [unsupported syntax](#unsupported)). There is also no down leveling, the JavaScript is preserved as is. | ||
:information_source: Not all TypeScript syntax is supported (see [unsupported syntax](#unsupported-syntax)). There is also no down-leveling; the JavaScript is preserved as is. | ||
@@ -70,8 +72,8 @@ ## Contents | ||
- [Node.js Loader](#nodejs-loader) | ||
- [Source Maps](#where-are-my-sourcemaps) | ||
- [SourceMaps](#where-are-my-sourcemaps) | ||
- [Implementation details](#does-it-really-just-blank-out-all-the-type-annotations) | ||
- [Unsupported syntax](#unsupported) | ||
- [Unsupported Syntax](#unsupported-syntax) | ||
- [tsconfig.json](#recommended-tsconfigjson-compiler-settings) | ||
- [TSX/JSX](#tsxjsx) | ||
- [ESM output](#ensuring-esm-output) | ||
- [ESM Output](#ensuring-esm-output) | ||
- [Contributions](#contributions) | ||
@@ -125,3 +127,3 @@ - [License](#license) | ||
# Example usage (Node.js v18.18): | ||
# Example usage (Node.js >= v18.20): | ||
$ node --import ts-blank-space/register ./path/to/your/file.ts | ||
@@ -136,4 +138,3 @@ ``` | ||
Because all the JavaScript in the output is located at the same line, column, and byte-offset as the original source | ||
there is no mapping information that is lost during the transform. | ||
Because all the JavaScript in the output is located at the same line, column, and byte-offset as the original source, no mapping information is lost during the transform. | ||
@@ -146,3 +147,3 @@ ## Does it really just blank out all the type annotations? | ||
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. | ||
@@ -169,6 +170,5 @@ Example input: | ||
If the annotation marking the return type of an arrow function introduces a new line before the `=>` | ||
then only replacing it with blank space would be incorrect. | ||
If the annotation marking the return type of an arrow function introduces a new line before the `=>`, then only replacing it with blank space would be incorrect. | ||
So in addition to removing the type annotation, the `)` is moved down to the end of the type annotation. | ||
Therefore, in addition to removing the type annotation, the `)` is moved down to the end of the type annotation. | ||
@@ -193,9 +193,7 @@ Example input: | ||
## Unsupported | ||
## Unsupported Syntax | ||
Some parts of TypeScript are not supported because they can't be erased in place due to having | ||
runtime semantics. See [unsupported_syntax.md](./docs/unsupported_syntax.md). | ||
Some parts of TypeScript are not supported because they can't be erased in place due to having runtime semantics. See [unsupported_syntax.md](./docs/unsupported_syntax.md). | ||
When unsupported syntax is encountered `ts-blank-space` will call the optional `onError` callback and continue. | ||
Examples can be seen in [`errors.test.js`](./tests/errors.test.js). | ||
When unsupported syntax is encountered, `ts-blank-space` will call the optional `onError` callback and continue. Examples can be seen in [`errors.test.ts`](./tests/errors.test.ts). | ||
@@ -219,6 +217,5 @@ ## Recommended `tsconfig.json` compiler settings | ||
`.tsx` input will be `.jsx` output because the JSX parts are not transformed, and instead preserved in the output. | ||
`.tsx` input will be `.jsx` output because the JSX parts are not transformed, but instead preserved in the output. | ||
By default `ts-blank-space` will parse the file assuming `.ts`. If the original file contains JSX syntax | ||
then the [parsing should be done manually](#bring-your-own-ast). There is a TSX example in [`valid.test.js`](./tests/valid.test.js). | ||
By default, `ts-blank-space` will parse the file assuming `.ts`. If the original file contains JSX syntax, then the [parsing should be done manually](#bring-your-own-ast). There is a TSX example in [`valid.test.ts`](./tests/valid.test.ts). | ||
@@ -229,3 +226,3 @@ ## Ensuring ESM output | ||
Because `ts-blank-space` only removes code this is not performed. To force the output to always have an ESM syntactic marker you can manually append `"export {};"`; | ||
Because `ts-blank-space` only removes code, this is not performed. To force the output to always have an ESM syntactic marker, you can manually append `"export {};"`; | ||
@@ -232,0 +229,0 @@ ## Contributions |
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
45026
666
243