Skip to content

Commit

Permalink
feat: graduate InlineJavaScriptCode and InlineTypeScriptCode to s…
Browse files Browse the repository at this point in the history
…table (#283)

BREAKING CHANGE: `InlineJsxCode` and `InlineTsxCode` classes have been removed. Use `InlineJavaScriptCode` or `InlineTypeScriptCode` respectively  and set `transformOptions.loader` to `jsx` or `tsx`.
  • Loading branch information
mrgrain authored Dec 18, 2022
1 parent 7159ef9 commit be31a04
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 220 deletions.
126 changes: 0 additions & 126 deletions API.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ export {
export {
TransformerProps,
InlineJavaScriptCode,
InlineJsxCode,
InlineTsxCode,
InlineTypeScriptCode,
} from './inline-code';

Expand Down
69 changes: 7 additions & 62 deletions src/inline-code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { TransformOptions, Loader } from './esbuild-types';
import { isEsbuildError } from './utils';

/**
* @stability experimental
* @stability stable
*/
export interface TransformerProps {
/**
Expand Down Expand Up @@ -115,14 +115,14 @@ function transformerProps(loader: Loader, props: TransformerProps = {}): Transfo
/**
* An implementation of `lambda.InlineCode` using the esbuild Transform API. Inline function code is limited to 4 KiB after transformation.
*
* @stability experimental
* @stability stable
*/
export class InlineJavaScriptCode extends BaseInlineCode {
public constructor(
/**
* The inline code to be transformed.
*
* @stability experimental
* @stability stable
*/
code: string,
/**
Expand All @@ -132,7 +132,7 @@ export class InlineJavaScriptCode extends BaseInlineCode {
* - `loader='js'`
*
* @see https://esbuild.github.io/api/#transform-api
* @stability experimental
* @stability stable
*/
props?: TransformerProps,
) {
Expand All @@ -141,45 +141,18 @@ export class InlineJavaScriptCode extends BaseInlineCode {
}
}

/**
* An implementation of `lambda.InlineCode` using the esbuild Transform API. Inline function code is limited to 4 KiB after transformation.
*
* @stability experimental
*/
export class InlineJsxCode extends BaseInlineCode {
public constructor(
/**
* The inline code to be transformed.
*
* @stability experimental
*/
code: string,
/**
* Props to change the behavior of the transformer.
*
* Default values for `transformOptions`:
* - `loader='jsx'`
*
* @see https://esbuild.github.io/api/#transform-api
* @stability experimental
*/
props?: TransformerProps,
) {
super(code, transformerProps('jsx', props));
}
}

/**
* An implementation of `lambda.InlineCode` using the esbuild Transform API. Inline function code is limited to 4 KiB after transformation.
*
* @stability experimental
* @stability stable
*/
export class InlineTypeScriptCode extends BaseInlineCode {
public constructor(
/**
* The inline code to be transformed.
*
* @stability experimental
* @stability stable
*/
code: string,
/**
Expand All @@ -189,38 +162,10 @@ export class InlineTypeScriptCode extends BaseInlineCode {
* - `loader='ts'`
*
* @see https://esbuild.github.io/api/#transform-api
* @stability experimental
* @stability stable
*/
props?: TransformerProps,
) {
super(code, transformerProps('ts', props));
}
}

/**
* An implementation of `lambda.InlineCode` using the esbuild Transform API. Inline function code is limited to 4 KiB after transformation.
*
* @stability experimental
*/
export class InlineTsxCode extends BaseInlineCode {
public constructor(
/**
* The inline code to be transformed.
*
* @stability experimental
*/
code: string,
/**
* Props to change the behavior of the transformer.
*
* Default values for `transformOptions`:
* - `loader='tsx'`
*
* @see https://esbuild.github.io/api/#transform-api
* @stability experimental
*/
props?: TransformerProps,
) {
super(code, transformerProps('tsx', props));
}
}
30 changes: 0 additions & 30 deletions test/inline-code.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import * as esbuild from 'esbuild';
import { mocked } from 'jest-mock';
import {
InlineJavaScriptCode,
InlineJsxCode,
InlineTsxCode,
InlineTypeScriptCode,
} from '../src';
import { EsbuildProvider } from '../src/esbuild-provider';
Expand All @@ -26,20 +24,6 @@ describe('using transformerProps', () => {
});
});

describe('given some jsx code', () => {
it('should transform the code', () => {
const code = new InlineJsxCode(
'const App = () => (<div>Hello World</div>)',
);

const { inlineCode } = code.bind(new Stack());

expect(inlineCode).toBe(
'const App = () => /* @__PURE__ */ React.createElement("div", null, "Hello World");\n',
);
});
});

describe('given some ts code', () => {
it('should transform the code', () => {
const code = new InlineTypeScriptCode('let x: number = 1');
Expand Down Expand Up @@ -98,20 +82,6 @@ describe('using transformerProps', () => {
});
});

describe('given some tsx code', () => {
it('should transform the code', () => {
const code = new InlineTsxCode(
'const App = (): JSX.Element => (<div>Hello World</div>)',
);

const { inlineCode } = code.bind(new Stack());

expect(inlineCode).toBe(
'const App = () => /* @__PURE__ */ React.createElement("div", null, "Hello World");\n',
);
});
});

describe('given some broken ts code', () => {
it('should throws', () => {
expect(() => {
Expand Down

0 comments on commit be31a04

Please sign in to comment.