File tree Expand file tree Collapse file tree 13 files changed +2370
-22
lines changed
Expand file tree Collapse file tree 13 files changed +2370
-22
lines changed Original file line number Diff line number Diff line change 1- node_modules
2- dist
1+ node_modules /
2+ dist /
3+ coverage /
Original file line number Diff line number Diff line change 88 "eslint:recommended",
99 "plugin:@typescript-eslint/recommended"
1010 ],
11+ "env": {
12+ "node": true
13+ },
1114 "rules": {
1215 "@typescript-eslint/no-unused-vars": ["error", { "args": "none" }]
1316 }
Original file line number Diff line number Diff line change 2424 cache : ' yarn'
2525 - run : yarn install --frozen-lockfile
2626 - run : yarn lint
27+ - run : yarn test
2728 - run : yarn build
Original file line number Diff line number Diff line change 11node_modules /
22dist /
3+ coverage /
34
45* .log
56* .swp
Original file line number Diff line number Diff line change 1313 "excludes" : [
1414 " **/node_modules" ,
1515 " **/*-lock.json" ,
16- " dist"
16+ " dist" ,
17+ " coverage"
1718 ],
1819 "plugins" : [
1920 " https://plugins.dprint.dev/typescript-0.62.2.wasm" ,
Original file line number Diff line number Diff line change 1+ /** @type {import('ts-jest/dist/types').InitialOptionsTsJest } */
2+ module . exports = {
3+ preset : 'ts-jest' ,
4+ testEnvironment : 'node' ,
5+ globals : {
6+ 'ts-jest' : {
7+ isolatedModules : true ,
8+ } ,
9+ } ,
10+ testPathIgnorePatterns : [ 'dist' ] ,
11+ } ;
Original file line number Diff line number Diff line change 2121 "build" : " rm -rf dist && npm run build:cjs && npm run build:ejs" ,
2222 "build:cjs" : " tsc --outDir dist/cjs --declaration" ,
2323 "build:ejs" : " tsc --outDir dist/ejs --module es6" ,
24+ "test" : " jest --coverage" ,
2425 "lint" : " dprint check && eslint ." ,
2526 "format" : " dprint fmt"
2627 },
28+ "files" : [" dist" ],
2729 "devDependencies" : {
30+ "@types/jest" : " ^27.4.0" ,
2831 "@typescript-eslint/eslint-plugin" : " ^5.10.2" ,
2932 "@typescript-eslint/parser" : " ^5.10.2" ,
3033 "dprint" : " ^0.22.0" ,
3134 "eslint" : " ^8.8.0" ,
35+ "jest" : " ^27.4.7" ,
36+ "ts-jest" : " ^27.1.3" ,
3237 "ttypescript" : " ^1.5.13" ,
3338 "typescript" : " ^4.5.5"
3439 },
Original file line number Diff line number Diff line change 1+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+ exports [` transform export const enum into object literal test-case/const-enum.d.ts 1` ] = `
4+ "export declare enum SomeEnum {
5+ A = 0 ,
6+ B = 1 ,
7+ C = \\" hello\\ " ,
8+ D = 1000 ,
9+ E = 1001
10+ }
11+ export declare enum ComputedEnum {
12+ A = 0 ,
13+ B = 1 ,
14+ C = 2 ,
15+ D = - 2 ,
16+ E = 4 ,
17+ F = - 1 ,
18+ G = 1228 ,
19+ H = 31 ,
20+ I = 230 ,
21+ J = \\" 12\\ " ,
22+ K = 1
23+ }
24+ export declare enum RegularEnum {
25+ A = 0 ,
26+ B = 1
27+ }
28+ "
29+ ` ;
30+
31+ exports [` transform export const enum into object literal test-case/const-enum.js 1` ] = `
32+ "export const SomeEnum = {
33+ A : 0 ,
34+ B : 1 ,
35+ C : \\" hello\\ " ,
36+ D : 1000 ,
37+ E : 1001
38+ } ;
39+ export const ComputedEnum = {
40+ A : 0 ,
41+ B : 1 ,
42+ C : 2 ,
43+ D : - 2 ,
44+ E : 4 ,
45+ F : - 1 ,
46+ G : 1228 ,
47+ H : 31 ,
48+ I : 230 ,
49+ J : \\" 12\\ " ,
50+ K : 1
51+ } ;
52+ export var RegularEnum;
53+ (function (RegularEnum) {
54+ RegularEnum [RegularEnum [\\" A\\ " ] = 0 ] = \\" A\\ " ;
55+ RegularEnum [RegularEnum [\\" B\\ " ] = 1 ] = \\" B\\ " ;
56+ } )(RegularEnum || (RegularEnum = { } ));
57+ "
58+ ` ;
Original file line number Diff line number Diff line change 1+ import ts from 'typescript' ;
2+ import transform from './transform' ;
3+
4+ describe ( 'transform export const enum into object literal' , ( ) => {
5+ const output = compile ( 'test-case/const-enum.ts' ) ;
6+
7+ for ( const [ fileName , content ] of Object . entries ( output ) ) {
8+ it ( fileName , ( ) => {
9+ expect ( content ) . toMatchSnapshot ( ) ;
10+ } ) ;
11+ }
12+ } ) ;
13+
14+ type Output = { [ fileName : string ] : string } ;
15+ function compile ( fileName : string ) : Output {
16+ const program = ts . createProgram ( {
17+ rootNames : [ fileName ] ,
18+ options : {
19+ target : ts . ScriptTarget . ES2015 ,
20+ module : ts . ModuleKind . ES2015 ,
21+ preserveConstEnums : true ,
22+ declaration : true ,
23+ moduleResolution : ts . ModuleResolutionKind . NodeJs ,
24+ } ,
25+ } ) ;
26+
27+ const transformer = transform ( program ) ;
28+ const output : Output = { } ;
29+
30+ program . emit (
31+ undefined ,
32+ ( fileName , data ) => {
33+ output [ fileName ] = ( output [ fileName ] || '' ) + data ;
34+ } ,
35+ undefined ,
36+ false ,
37+ {
38+ before : [ transformer ] ,
39+ afterDeclarations : [ transformer as any ] ,
40+ } ,
41+ ) ;
42+
43+ return output ;
44+ }
Original file line number Diff line number Diff line change 11import ts from 'typescript' ;
22import { evaluate , hasModifier } from './utils' ;
33
4- export default function ( program : ts . Program , pluginOptions : unknown ) {
4+ export default function ( program : ts . Program , pluginOptions ? : unknown ) {
55 return ( ctx : ts . TransformationContext ) => {
66 return ( sourceFile : ts . SourceFile ) => {
77 const ambient = sourceFile . isDeclarationFile ;
You can’t perform that action at this time.
0 commit comments