Mirror: 🎩 A tiny but capable push & pull stream library for TypeScript and Flow

fix: Compile away internal TalkbackKind and SignalKind enums (#154)

Changed files
+63 -31
.changeset
scripts
src
+5
.changeset/dry-pants-judge.md
···
···
+
---
+
'wonka': patch
+
---
+
+
Fix internal `SignalKind` and `TalkbackKind` enums not compiling away.
+46 -29
scripts/rollup.config.mjs
···
import dts from 'rollup-plugin-dts';
import flowTypings from './flow-typings-plugin.mjs';
const commonPlugins = [
resolve({
···
},
exclude: 'node_modules/**',
}),
-
-
terser({
-
warnings: true,
-
ecma: 2015,
-
keep_fnames: true,
-
ie8: false,
-
compress: {
-
pure_getters: true,
-
toplevel: true,
-
booleans_as_integers: false,
-
keep_fnames: true,
-
keep_fargs: true,
-
if_return: false,
-
ie8: false,
-
sequences: false,
-
loops: false,
-
conditionals: false,
-
join_vars: false,
-
},
-
mangle: {
-
module: true,
-
keep_fnames: true,
-
},
-
output: {
-
beautify: true,
-
braces: true,
-
indent_level: 2,
-
},
-
}),
];
const dtsPlugins = [
···
objectShorthand: false,
constBindings: false,
},
};
};
···
import dts from 'rollup-plugin-dts';
import flowTypings from './flow-typings-plugin.mjs';
+
import * as types from '../src/types.mjs';
+
+
const minify = terser({
+
warnings: true,
+
ecma: 2015,
+
keep_fnames: true,
+
ie8: false,
+
compress: {
+
pure_getters: true,
+
toplevel: true,
+
booleans_as_integers: false,
+
keep_fnames: true,
+
keep_fargs: true,
+
if_return: false,
+
ie8: false,
+
sequences: false,
+
loops: false,
+
conditionals: false,
+
join_vars: false,
+
},
+
mangle: {
+
module: true,
+
keep_fnames: true,
+
},
+
output: {
+
beautify: true,
+
braces: true,
+
indent_level: 2,
+
},
+
});
const commonPlugins = [
resolve({
···
},
exclude: 'node_modules/**',
}),
];
const dtsPlugins = [
···
objectShorthand: false,
constBindings: false,
},
+
plugins: [
+
{
+
renderChunk(code, _chunk) {
+
const kinds = Object.keys(types);
+
const members = Object.values(types)
+
.reduce((acc, item) => [...acc, ...Object.keys(item)], [])
+
const enumRe = new RegExp(`(${kinds.join('|')})[.](${members.join('|')})`, 'g')
+
return code.replace(enumRe, (match, kind, member) => {
+
const value = (types[kind] && types[kind][member]);
+
return value != null ? '' + value : match;
+
});
+
},
+
},
+
+
minify,
+
]
};
};
+10
src/types.mjs
···
···
+
export const TalkbackKind = {
+
Pull: 0,
+
Close: 1,
+
};
+
+
export const SignalKind = {
+
Start: 0,
+
Push: 1,
+
End: 0,
+
};
+2 -2
src/types.ts src/types.d.ts
···
* the {@link Start} signal, to tell a {@link Source} to either send a new value (pulling) or stop
* sending values altogether (cancellation).
*/
-
export const enum TalkbackKind {
/** Instructs the {@link Source} to send the next value. */
Pull = 0,
/** Instructs the {@link Source} to stop sending values and cancels it. */
···
* @see {@link Start} for the data structure of the start signal.
* @see {@link Push} for the data structure of the push signal, carrying values.
*/
-
export const enum SignalKind {
/**
* Informs the {@link Sink} that it's being called by a {@link Source}.
*
···
* the {@link Start} signal, to tell a {@link Source} to either send a new value (pulling) or stop
* sending values altogether (cancellation).
*/
+
export enum TalkbackKind {
/** Instructs the {@link Source} to send the next value. */
Pull = 0,
/** Instructs the {@link Source} to stop sending values and cancels it. */
···
* @see {@link Start} for the data structure of the start signal.
* @see {@link Push} for the data structure of the push signal, carrying values.
*/
+
export enum SignalKind {
/**
* Informs the {@link Sink} that it's being called by a {@link Source}.
*