Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: graduate InlineJavaScriptCode and InlineTypeScriptCode to stable #283

Merged
merged 1 commit into from
Dec 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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