Skip to content

Commit

Permalink
Update deps, initial TypeScript and ECMAScript Next support in CSF files
Browse files Browse the repository at this point in the history
  • Loading branch information
sapegin committed Feb 26, 2021
1 parent 3bd9310 commit c638814
Show file tree
Hide file tree
Showing 8 changed files with 10,152 additions and 14,689 deletions.
24,539 changes: 10,004 additions & 14,535 deletions package-lock.json

Large diffs are not rendered by default.

157 changes: 79 additions & 78 deletions package.json
Expand Up @@ -27,147 +27,148 @@
"node": ">=10"
},
"dependencies": {
"@mdx-js/mdx": "^1.6.19",
"@mdx-js/react": "^1.6.19",
"@mdx-js/mdx": "^1.6.22",
"@mdx-js/react": "^1.6.22",
"@tippyjs/react": "4.1.0",
"@vxna/mini-html-webpack-template": "^2.0.0",
"acorn": "^6.4.2",
"acorn": "^8.0.5",
"acorn-jsx": "^5.3.1",
"acorn-loose": "^8.0.2",
"assert": "1.5.0",
"ast-types": "~0.14.2",
"clean-webpack-plugin": "^3.0.0",
"clipboard-copy": "^3.1.0",
"clsx": "^1.0.4",
"clipboard-copy": "^3.2.0",
"clsx": "^1.1.1",
"common-dir": "^3.0.0",
"copy-webpack-plugin": "^6.1.0",
"core-js": "^3.6.4",
"copy-webpack-plugin": "^6.4.1",
"core-js": "^3.9.0",
"doctrine": "^3.0.0",
"es6-object-assign": "~1.1.0",
"es6-promise": "^4.2.8",
"escodegen": "^2.0.0",
"estree-walker": "~2.0.1",
"fastest-levenshtein": "^1.0.9",
"estree-walker": "~2.0.2",
"fastest-levenshtein": "^1.0.12",
"findup": "^0.1.5",
"function.name-polyfill": "^1.0.6",
"github-slugger": "^1.2.1",
"glob": "^7.1.5",
"github-slugger": "^1.3.0",
"glob": "^7.1.6",
"glogg": "^1.0.2",
"hash-sum": "^2.0.0",
"is-directory": "^0.3.1",
"javascript-stringify": "^2.0.0",
"jss": "^10.0.0",
"jss-plugin-camel-case": "^10.0.0",
"jss-plugin-compose": "^10.0.0",
"jss-plugin-default-unit": "^10.0.0",
"jss-plugin-global": "^10.0.0",
"jss-plugin-isolate": "^10.0.0",
"jss-plugin-nested": "^10.0.0",
"javascript-stringify": "^2.0.1",
"jss": "^10.5.1",
"jss-plugin-camel-case": "^10.5.1",
"jss-plugin-compose": "^10.5.1",
"jss-plugin-default-unit": "^10.5.1",
"jss-plugin-global": "^10.5.1",
"jss-plugin-isolate": "^10.5.1",
"jss-plugin-nested": "^10.5.1",
"kleur": "^3.0.3",
"listify": "^1.0.0",
"listify": "^1.0.3",
"loader-utils": "^2.0.0",
"lodash": "^4.17.15",
"lodash": "^4.17.21",
"lowercase-keys": "^2.0.0",
"markdown-to-jsx": "^7.1.0",
"markdown-to-jsx": "^7.1.1",
"mini-html-webpack-plugin": "^3.1.3",
"mri": "^1.1.4",
"ora": "^4.0.2",
"prism-react-renderer": "^1.1.1",
"mri": "^1.1.6",
"ora": "^4.1.1",
"prism-react-renderer": "^1.2.0",
"prop-types": "^15.7.2",
"q-i": "^2.0.1",
"qss": "^2.0.3",
"react-dev-utils": "^11.0.0",
"react-docgen": "^5.3.0",
"react-dev-utils": "^11.0.3",
"react-docgen": "^5.3.1",
"react-docgen-annotation-resolver": "^2.0.0",
"react-docgen-displayname-handler": "^3.0.2",
"react-group": "^3.0.2",
"react-icons": "^3.8.0",
"react-icons": "^3.11.0",
"react-simple-code-editor": "^0.11.0",
"recast": "~0.20.3",
"recast": "~0.20.4",
"remark": "^13.0.0",
"sucrase": "^3.15.0",
"sucrase": "^3.17.1",
"terser-webpack-plugin": "^4.2.3",
"to-ast": "^1.0.0",
"type-detect": "^4.0.8",
"unindent": "^2.0.0",
"unist-util-visit": "^2.0.0",
"webpack-dev-server": "^3.11.0",
"unist-util-visit": "^2.0.3",
"webpack-dev-server": "^3.11.2",
"webpack-merge": "^4.2.2"
},
"peerDependencies": {
"react": ">=16.8",
"react-dom": ">=16.8"
},
"devDependencies": {
"@babel/cli": "^7.8.4",
"@babel/core": "^7.9.0",
"@babel/plugin-proposal-class-properties": "^7.8.3",
"@babel/preset-env": "^7.9.0",
"@babel/preset-flow": "^7.9.0",
"@babel/preset-react": "^7.9.4",
"@babel/preset-typescript": "^7.9.0",
"@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^11.1.0",
"@babel/cli": "^7.13.0",
"@babel/core": "^7.13.1",
"@babel/plugin-proposal-class-properties": "^7.13.0",
"@babel/preset-env": "^7.13.5",
"@babel/preset-flow": "^7.12.13",
"@babel/preset-react": "^7.12.13",
"@babel/preset-typescript": "^7.13.0",
"@testing-library/jest-dom": "^5.11.9",
"@testing-library/react": "^11.2.5",
"@types/copy-webpack-plugin": "^5.0.2",
"@types/doctrine": "0.0.3",
"@types/enzyme": "^3.10.3",
"@types/enzyme": "^3.10.8",
"@types/escodegen": "0.0.6",
"@types/estree": "^0.0.45",
"@types/estree": "^0.0.46",
"@types/hash-sum": "^1.0.0",
"@types/jest": "^26.0.14",
"@types/jest": "^26.0.20",
"@types/keymirror": "^0.1.1",
"@types/loader-utils": "^1.1.3",
"@types/lodash": "^4.14.144",
"@types/markdown-to-jsx": "^6.9.0",
"@types/node": "^12.12.3",
"@types/react": "^16.9.27",
"@types/react-dom": "^16.9.5",
"@types/loader-utils": "^1.1.4",
"@types/lodash": "^4.14.168",
"@types/markdown-to-jsx": "^6.11.3",
"@types/node": "^12.20.4",
"@types/react": "^16.14.4",
"@types/react-dom": "^16.9.11",
"@types/terser-webpack-plugin": "^2.2.0",
"@types/type-detect": "^4.0.1",
"@types/unist": "^2.0.3",
"@types/webpack-dev-server": "^3.11.1",
"@types/webpack-env": "^1.14.1",
"@typescript-eslint/eslint-plugin": "^4.4.1",
"@typescript-eslint/parser": "^4.4.1",
"@types/webpack-env": "^1.16.0",
"@typescript-eslint/eslint-plugin": "^4.15.2",
"@typescript-eslint/parser": "^4.15.2",
"babel-core": "^7.0.0-bridge.0",
"babel-eslint": "^10.1.0",
"babel-jest": "^26.6.0",
"babel-loader": "^8.1.0",
"cheerio": "^1.0.0-rc.3",
"css-loader": "^3.2.0",
"babel-jest": "^26.6.3",
"babel-loader": "^8.2.2",
"cheerio": "^1.0.0-rc.5",
"css-loader": "^3.6.0",
"deabsdeep": "^1.0.6",
"deepfreeze": "^2.0.0",
"dog-names": "^2.0.0",
"enzyme": "^3.10.0",
"enzyme-adapter-react-16": "^1.15.1",
"enzyme-to-json": "^3.4.3",
"eslint": "^7.11.0",
"enzyme": "^3.11.0",
"enzyme-adapter-react-16": "^1.15.6",
"enzyme-to-json": "^3.6.1",
"eslint": "^7.20.0",
"eslint-config-tamia": "^7.2.6",
"eslint-import-resolver-typescript": "^2.3.0",
"eslint-plugin-compat": "^3.8.0",
"eslint-import-resolver-typescript": "^2.4.0",
"eslint-plugin-compat": "^3.9.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jsx-a11y": "^6.3.1",
"eslint-plugin-react": "^7.21.4",
"eslint-plugin-jsx-a11y": "^6.4.1",
"eslint-plugin-react": "^7.22.0",
"express": "^4.17.1",
"file-loader": "^4.2.0",
"fs-extra": "^9.0.0",
"husky": "^4.3.0",
"jest": "^26.6.0",
"file-loader": "^4.3.0",
"fs-extra": "^9.1.0",
"husky": "^4.3.8",
"jest": "^26.6.3",
"jest-serializer-html": "^7.0.0",
"keymirror": "^0.1.1",
"lint-staged": "^10.5.1",
"lint-staged": "^10.5.4",
"memfs": "~2.15.5",
"prettier": "2.1.2",
"raf": "^3.4.1",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-test-renderer": "^16.13.1",
"react": "^16.14.0",
"react-dom": "^16.14.0",
"react-test-renderer": "^16.14.0",
"strip-shebang": "^1.0.2",
"style-loader": "^1.0.0",
"style-loader": "^1.3.0",
"tapable": "^1.1.3",
"typescript": "^3.9.0",
"url-loader": "^2.2.0",
"webpack": "^4.44.2",
"webpack-cli": "^3.3.9"
"typescript": "^3.9.9",
"url-loader": "^2.3.0",
"webpack": "^4.46.0",
"webpack-cli": "^3.3.12"
},
"scripts": {
"pretest": "npm run lint && npm run typecheck",
Expand Down
24 changes: 24 additions & 0 deletions src/loaders/rehype/__tests__/exportStories.spec.ts
Expand Up @@ -514,4 +514,28 @@ export const basic = () => <Container>{pizza}</Container>
"
`);
});

test('understands TypeScript', async () => {
const result = await compile(
`Henlo`,
`
const nums = ['eins', 'zwei', 'polizei'] as const;
export const basic = () => <Container>{nums.map(x => x)}</Container>
`
);
expect(result).toMatchInlineSnapshot(`
"
export const __namedExamples = {
'basic': 'const nums = [\\\\'eins\\\\', \\\\'zwei\\\\', \\\\'polizei\\\\'];\\\\n\\\\n<Container>{nums.map(x => x)}</Container>'
};
export const __storiesScope = {};
const layoutProps = {
__namedExamples,
__storiesScope
};
"
`);
});
});
24 changes: 14 additions & 10 deletions src/loaders/rehype/exportStories.ts
Expand Up @@ -146,7 +146,6 @@ const getVariableDeclarationNames = ({ id }: VariableDeclarator): string[] => {
}
return '';
}

return '';
})
.filter(Boolean);
Expand All @@ -156,16 +155,21 @@ const getVariableDeclarationNames = ({ id }: VariableDeclarator): string[] => {
};

const getVariableStatements = (ast: Program, code: string): Dependency[] => {
const nodes = ast.body.filter((node) => node.type === 'VariableDeclaration');
return nodes.map((node) => {
const variableDeclarationNode = node as VariableDeclaration;
// @ts-expect-error: There are no types for location ;-/
const { start, end } = variableDeclarationNode;
return {
names: flatMap(variableDeclarationNode.declarations, getVariableDeclarationNames),
code: code.substring(start, end),
};
const variables: Dependency[] = [];
walk(ast, {
enter: (node: BaseNode, parent: BaseNode) => {
if (node.type === 'VariableDeclaration' && parent.type === 'Program') {
const variableDeclarationNode = node as VariableDeclaration;
// @ts-expect-error: There are no types for location ;-/
const { start, end } = variableDeclarationNode;
variables.push({
names: flatMap(variableDeclarationNode.declarations, getVariableDeclarationNames),
code: code.substring(start, end),
});
}
},
});
return variables;
};

const getExportCode = (node: Declaration, code: string) => {
Expand Down
60 changes: 0 additions & 60 deletions src/loaders/utils/__tests__/__snapshots__/getAst.spec.ts.snap

This file was deleted.

14 changes: 12 additions & 2 deletions src/loaders/utils/__tests__/getAst.spec.ts
Expand Up @@ -4,11 +4,21 @@ import getAst from '../getAst';
describe('getAst', () => {
test('return AST', () => {
const result = getAst(`42`);
expect(result).toMatchSnapshot();
expect(result).toHaveProperty('type', 'Program');
});

test('accept Acorn plugins', () => {
const result = getAst(`<X />`, [acornJsx()]);
expect(result).toMatchSnapshot();
expect(result).toHaveProperty('type', 'Program');
});

test('understands new ECMAScript syntax', () => {
const result = getAst(`foo?.bar?.baz()`);
expect(result).toHaveProperty('type', 'Program');
});

test('understands TypeScript', () => {
const result = getAst(`const pizza = [1, 2, 3] as const`);
expect(result).toHaveProperty('type', 'Program');
});
});

0 comments on commit c638814

Please sign in to comment.