@storybook/react 6.5.9 → 7.0.0-alpha.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -47
- package/dist/chunk-DGYCFUMN.mjs +1 -0
- package/dist/config.d.ts +24 -0
- package/dist/config.js +7 -0
- package/dist/config.mjs +7 -0
- package/dist/index.d.ts +173 -0
- package/dist/index.js +1 -0
- package/dist/index.mjs +1 -0
- package/dist/types-9f8d440a.d.ts +17 -0
- package/package.json +38 -61
- package/preview.js +1 -0
- package/bin/build.js +0 -4
- package/bin/index.js +0 -3
- package/demo.d.ts +0 -32
- package/demo.js +0 -5
- package/dist/cjs/client/docs/config.js +0 -29
- package/dist/cjs/client/docs/extractArgTypes.js +0 -54
- package/dist/cjs/client/docs/extractProps.js +0 -77
- package/dist/cjs/client/docs/jsxDecorator.js +0 -277
- package/dist/cjs/client/docs/lib/captions.js +0 -18
- package/dist/cjs/client/docs/lib/componentTypes.js +0 -24
- package/dist/cjs/client/docs/lib/defaultValues/createDefaultValue.js +0 -81
- package/dist/cjs/client/docs/lib/defaultValues/createFromRawDefaultProp.js +0 -225
- package/dist/cjs/client/docs/lib/defaultValues/generateArray.js +0 -29
- package/dist/cjs/client/docs/lib/defaultValues/generateObject.js +0 -29
- package/dist/cjs/client/docs/lib/defaultValues/index.js +0 -37
- package/dist/cjs/client/docs/lib/defaultValues/prettyIdentifier.js +0 -34
- package/dist/cjs/client/docs/lib/generateCode.js +0 -89
- package/dist/cjs/client/docs/lib/index.js +0 -63
- package/dist/cjs/client/docs/lib/inspection/acornParser.js +0 -254
- package/dist/cjs/client/docs/lib/inspection/index.js +0 -37
- package/dist/cjs/client/docs/lib/inspection/inspectValue.js +0 -26
- package/dist/cjs/client/docs/lib/inspection/types.js +0 -19
- package/dist/cjs/client/docs/lib/isHtmlTag.js +0 -18
- package/dist/cjs/client/docs/propTypes/createType.js +0 -469
- package/dist/cjs/client/docs/propTypes/generateFuncSignature.js +0 -78
- package/dist/cjs/client/docs/propTypes/handleProp.js +0 -54
- package/dist/cjs/client/docs/propTypes/rawDefaultPropResolvers.js +0 -47
- package/dist/cjs/client/docs/propTypes/sortProps.js +0 -37
- package/dist/cjs/client/docs/react-argtypes.stories.js +0 -129
- package/dist/cjs/client/docs/typeScript/handleProp.js +0 -38
- package/dist/cjs/client/index.js +0 -103
- package/dist/cjs/client/preview/config.js +0 -25
- package/dist/cjs/client/preview/globals.js +0 -11
- package/dist/cjs/client/preview/index.js +0 -52
- package/dist/cjs/client/preview/render.js +0 -296
- package/dist/cjs/client/preview/types-6-0.js +0 -5
- package/dist/cjs/client/preview/types-6-3.js +0 -24
- package/dist/cjs/client/preview/types-7-0.js +0 -5
- package/dist/cjs/client/preview/types.js +0 -5
- package/dist/cjs/client/testing/index.js +0 -112
- package/dist/cjs/demo/Button.js +0 -37
- package/dist/cjs/demo/Welcome.js +0 -126
- package/dist/cjs/server/build.js +0 -9
- package/dist/cjs/server/cra-config.js +0 -69
- package/dist/cjs/server/framework-preset-cra.js +0 -35
- package/dist/cjs/server/framework-preset-react-docs.js +0 -68
- package/dist/cjs/server/framework-preset-react-dom-hack.js +0 -31
- package/dist/cjs/server/framework-preset-react.js +0 -98
- package/dist/cjs/server/index.js +0 -9
- package/dist/cjs/server/options.js +0 -17
- package/dist/cjs/server/preset.js +0 -16
- package/dist/esm/client/docs/config.js +0 -16
- package/dist/esm/client/docs/extractArgTypes.js +0 -39
- package/dist/esm/client/docs/extractProps.js +0 -54
- package/dist/esm/client/docs/jsxDecorator.js +0 -218
- package/dist/esm/client/docs/lib/captions.js +0 -6
- package/dist/esm/client/docs/lib/componentTypes.js +0 -9
- package/dist/esm/client/docs/lib/defaultValues/createDefaultValue.js +0 -67
- package/dist/esm/client/docs/lib/defaultValues/createFromRawDefaultProp.js +0 -191
- package/dist/esm/client/docs/lib/defaultValues/generateArray.js +0 -19
- package/dist/esm/client/docs/lib/defaultValues/generateObject.js +0 -19
- package/dist/esm/client/docs/lib/defaultValues/index.js +0 -2
- package/dist/esm/client/docs/lib/defaultValues/prettyIdentifier.js +0 -22
- package/dist/esm/client/docs/lib/generateCode.js +0 -68
- package/dist/esm/client/docs/lib/index.js +0 -4
- package/dist/esm/client/docs/lib/inspection/acornParser.js +0 -213
- package/dist/esm/client/docs/lib/inspection/index.js +0 -2
- package/dist/esm/client/docs/lib/inspection/inspectValue.js +0 -16
- package/dist/esm/client/docs/lib/inspection/types.js +0 -12
- package/dist/esm/client/docs/lib/isHtmlTag.js +0 -6
- package/dist/esm/client/docs/propTypes/createType.js +0 -449
- package/dist/esm/client/docs/propTypes/generateFuncSignature.js +0 -62
- package/dist/esm/client/docs/propTypes/handleProp.js +0 -39
- package/dist/esm/client/docs/propTypes/rawDefaultPropResolvers.js +0 -32
- package/dist/esm/client/docs/propTypes/sortProps.js +0 -24
- package/dist/esm/client/docs/react-argtypes.stories.js +0 -97
- package/dist/esm/client/docs/typeScript/handleProp.js +0 -27
- package/dist/esm/client/index.js +0 -7
- package/dist/esm/client/preview/config.js +0 -4
- package/dist/esm/client/preview/globals.js +0 -6
- package/dist/esm/client/preview/index.js +0 -29
- package/dist/esm/client/preview/render.js +0 -255
- package/dist/esm/client/preview/types-6-0.js +0 -1
- package/dist/esm/client/preview/types-6-3.js +0 -10
- package/dist/esm/client/preview/types-7-0.js +0 -1
- package/dist/esm/client/preview/types.js +0 -1
- package/dist/esm/client/testing/index.js +0 -96
- package/dist/esm/demo/Button.js +0 -26
- package/dist/esm/demo/Welcome.js +0 -114
- package/dist/esm/server/build.js +0 -3
- package/dist/esm/server/cra-config.js +0 -49
- package/dist/esm/server/framework-preset-cra.js +0 -25
- package/dist/esm/server/framework-preset-react-docs.js +0 -49
- package/dist/esm/server/framework-preset-react-dom-hack.js +0 -21
- package/dist/esm/server/framework-preset-react.js +0 -78
- package/dist/esm/server/index.js +0 -3
- package/dist/esm/server/options.js +0 -8
- package/dist/esm/server/preset.js +0 -5
- package/dist/modern/client/docs/config.js +0 -14
- package/dist/modern/client/docs/extractArgTypes.js +0 -38
- package/dist/modern/client/docs/extractProps.js +0 -42
- package/dist/modern/client/docs/jsxDecorator.js +0 -177
- package/dist/modern/client/docs/lib/captions.js +0 -6
- package/dist/modern/client/docs/lib/componentTypes.js +0 -2
- package/dist/modern/client/docs/lib/defaultValues/createDefaultValue.js +0 -72
- package/dist/modern/client/docs/lib/defaultValues/createFromRawDefaultProp.js +0 -181
- package/dist/modern/client/docs/lib/defaultValues/generateArray.js +0 -21
- package/dist/modern/client/docs/lib/defaultValues/generateObject.js +0 -21
- package/dist/modern/client/docs/lib/defaultValues/index.js +0 -2
- package/dist/modern/client/docs/lib/defaultValues/prettyIdentifier.js +0 -24
- package/dist/modern/client/docs/lib/generateCode.js +0 -59
- package/dist/modern/client/docs/lib/index.js +0 -4
- package/dist/modern/client/docs/lib/inspection/acornParser.js +0 -211
- package/dist/modern/client/docs/lib/inspection/index.js +0 -2
- package/dist/modern/client/docs/lib/inspection/inspectValue.js +0 -15
- package/dist/modern/client/docs/lib/inspection/types.js +0 -12
- package/dist/modern/client/docs/lib/isHtmlTag.js +0 -4
- package/dist/modern/client/docs/propTypes/createType.js +0 -446
- package/dist/modern/client/docs/propTypes/generateFuncSignature.js +0 -57
- package/dist/modern/client/docs/propTypes/handleProp.js +0 -39
- package/dist/modern/client/docs/propTypes/rawDefaultPropResolvers.js +0 -31
- package/dist/modern/client/docs/propTypes/sortProps.js +0 -14
- package/dist/modern/client/docs/react-argtypes.stories.js +0 -54
- package/dist/modern/client/docs/typeScript/handleProp.js +0 -28
- package/dist/modern/client/index.js +0 -7
- package/dist/modern/client/preview/config.js +0 -4
- package/dist/modern/client/preview/globals.js +0 -8
- package/dist/modern/client/preview/index.js +0 -21
- package/dist/modern/client/preview/render.js +0 -141
- package/dist/modern/client/preview/types-6-0.js +0 -1
- package/dist/modern/client/preview/types-6-3.js +0 -10
- package/dist/modern/client/preview/types-7-0.js +0 -1
- package/dist/modern/client/preview/types.js +0 -1
- package/dist/modern/client/testing/index.js +0 -96
- package/dist/modern/demo/Button.js +0 -25
- package/dist/modern/demo/Welcome.js +0 -108
- package/dist/modern/server/build.js +0 -3
- package/dist/modern/server/cra-config.js +0 -49
- package/dist/modern/server/framework-preset-cra.js +0 -25
- package/dist/modern/server/framework-preset-react-docs.js +0 -49
- package/dist/modern/server/framework-preset-react-dom-hack.js +0 -21
- package/dist/modern/server/framework-preset-react.js +0 -78
- package/dist/modern/server/index.js +0 -3
- package/dist/modern/server/options.js +0 -8
- package/dist/modern/server/preset.js +0 -5
- package/dist/ts3.4/client/docs/config.d.ts +0 -13
- package/dist/ts3.4/client/docs/extractArgTypes.d.ts +0 -2
- package/dist/ts3.4/client/docs/extractProps.d.ts +0 -5
- package/dist/ts3.4/client/docs/jsxDecorator.d.ts +0 -23
- package/dist/ts3.4/client/docs/lib/captions.d.ts +0 -6
- package/dist/ts3.4/client/docs/lib/componentTypes.d.ts +0 -2
- package/dist/ts3.4/client/docs/lib/defaultValues/createDefaultValue.d.ts +0 -2
- package/dist/ts3.4/client/docs/lib/defaultValues/createFromRawDefaultProp.d.ts +0 -11
- package/dist/ts3.4/client/docs/lib/defaultValues/generateArray.d.ts +0 -3
- package/dist/ts3.4/client/docs/lib/defaultValues/generateObject.d.ts +0 -3
- package/dist/ts3.4/client/docs/lib/defaultValues/index.d.ts +0 -2
- package/dist/ts3.4/client/docs/lib/defaultValues/prettyIdentifier.d.ts +0 -4
- package/dist/ts3.4/client/docs/lib/generateCode.d.ts +0 -3
- package/dist/ts3.4/client/docs/lib/index.d.ts +0 -4
- package/dist/ts3.4/client/docs/lib/inspection/acornParser.d.ts +0 -7
- package/dist/ts3.4/client/docs/lib/inspection/index.d.ts +0 -2
- package/dist/ts3.4/client/docs/lib/inspection/inspectValue.d.ts +0 -2
- package/dist/ts3.4/client/docs/lib/inspection/types.d.ts +0 -50
- package/dist/ts3.4/client/docs/lib/isHtmlTag.d.ts +0 -1
- package/dist/ts3.4/client/docs/propTypes/createType.d.ts +0 -2
- package/dist/ts3.4/client/docs/propTypes/generateFuncSignature.d.ts +0 -4
- package/dist/ts3.4/client/docs/propTypes/handleProp.d.ts +0 -5
- package/dist/ts3.4/client/docs/propTypes/rawDefaultPropResolvers.d.ts +0 -1
- package/dist/ts3.4/client/docs/propTypes/sortProps.d.ts +0 -4
- package/dist/ts3.4/client/docs/react-argtypes.stories.d.ts +0 -1
- package/dist/ts3.4/client/docs/typeScript/handleProp.d.ts +0 -3
- package/dist/ts3.4/client/index.d.ts +0 -4
- package/dist/ts3.4/client/preview/config.d.ts +0 -4
- package/dist/ts3.4/client/preview/globals.d.ts +0 -1
- package/dist/ts3.4/client/preview/index.d.ts +0 -25
- package/dist/ts3.4/client/preview/render.d.ts +0 -5
- package/dist/ts3.4/client/preview/types-6-0.d.ts +0 -35
- package/dist/ts3.4/client/preview/types-6-3.d.ts +0 -40
- package/dist/ts3.4/client/preview/types-7-0.d.ts +0 -21
- package/dist/ts3.4/client/preview/types.d.ts +0 -16
- package/dist/ts3.4/client/testing/index.d.ts +0 -84
- package/dist/ts3.4/demo/Button.d.ts +0 -4
- package/dist/ts3.4/demo/Welcome.d.ts +0 -6
- package/dist/ts3.4/server/build.d.ts +0 -1
- package/dist/ts3.4/server/cra-config.d.ts +0 -4
- package/dist/ts3.4/server/framework-preset-cra.d.ts +0 -3
- package/dist/ts3.4/server/framework-preset-react-docs.d.ts +0 -6
- package/dist/ts3.4/server/framework-preset-react-dom-hack.d.ts +0 -32
- package/dist/ts3.4/server/framework-preset-react.d.ts +0 -6
- package/dist/ts3.4/server/index.d.ts +0 -1
- package/dist/ts3.4/server/options.d.ts +0 -3
- package/dist/ts3.4/server/preset.d.ts +0 -3
- package/dist/ts3.9/client/docs/config.d.ts +0 -13
- package/dist/ts3.9/client/docs/extractArgTypes.d.ts +0 -2
- package/dist/ts3.9/client/docs/extractProps.d.ts +0 -5
- package/dist/ts3.9/client/docs/jsxDecorator.d.ts +0 -23
- package/dist/ts3.9/client/docs/lib/captions.d.ts +0 -6
- package/dist/ts3.9/client/docs/lib/componentTypes.d.ts +0 -2
- package/dist/ts3.9/client/docs/lib/defaultValues/createDefaultValue.d.ts +0 -2
- package/dist/ts3.9/client/docs/lib/defaultValues/createFromRawDefaultProp.d.ts +0 -11
- package/dist/ts3.9/client/docs/lib/defaultValues/generateArray.d.ts +0 -3
- package/dist/ts3.9/client/docs/lib/defaultValues/generateObject.d.ts +0 -3
- package/dist/ts3.9/client/docs/lib/defaultValues/index.d.ts +0 -2
- package/dist/ts3.9/client/docs/lib/defaultValues/prettyIdentifier.d.ts +0 -4
- package/dist/ts3.9/client/docs/lib/generateCode.d.ts +0 -3
- package/dist/ts3.9/client/docs/lib/index.d.ts +0 -4
- package/dist/ts3.9/client/docs/lib/inspection/acornParser.d.ts +0 -7
- package/dist/ts3.9/client/docs/lib/inspection/index.d.ts +0 -2
- package/dist/ts3.9/client/docs/lib/inspection/inspectValue.d.ts +0 -2
- package/dist/ts3.9/client/docs/lib/inspection/types.d.ts +0 -50
- package/dist/ts3.9/client/docs/lib/isHtmlTag.d.ts +0 -1
- package/dist/ts3.9/client/docs/propTypes/createType.d.ts +0 -2
- package/dist/ts3.9/client/docs/propTypes/generateFuncSignature.d.ts +0 -4
- package/dist/ts3.9/client/docs/propTypes/handleProp.d.ts +0 -5
- package/dist/ts3.9/client/docs/propTypes/rawDefaultPropResolvers.d.ts +0 -1
- package/dist/ts3.9/client/docs/propTypes/sortProps.d.ts +0 -4
- package/dist/ts3.9/client/docs/react-argtypes.stories.d.ts +0 -1
- package/dist/ts3.9/client/docs/typeScript/handleProp.d.ts +0 -3
- package/dist/ts3.9/client/index.d.ts +0 -4
- package/dist/ts3.9/client/preview/config.d.ts +0 -4
- package/dist/ts3.9/client/preview/globals.d.ts +0 -1
- package/dist/ts3.9/client/preview/index.d.ts +0 -25
- package/dist/ts3.9/client/preview/render.d.ts +0 -5
- package/dist/ts3.9/client/preview/types-6-0.d.ts +0 -35
- package/dist/ts3.9/client/preview/types-6-3.d.ts +0 -40
- package/dist/ts3.9/client/preview/types-7-0.d.ts +0 -21
- package/dist/ts3.9/client/preview/types.d.ts +0 -16
- package/dist/ts3.9/client/testing/index.d.ts +0 -84
- package/dist/ts3.9/demo/Button.d.ts +0 -4
- package/dist/ts3.9/demo/Welcome.d.ts +0 -6
- package/dist/ts3.9/server/build.d.ts +0 -1
- package/dist/ts3.9/server/cra-config.d.ts +0 -4
- package/dist/ts3.9/server/framework-preset-cra.d.ts +0 -3
- package/dist/ts3.9/server/framework-preset-react-docs.d.ts +0 -6
- package/dist/ts3.9/server/framework-preset-react-dom-hack.d.ts +0 -32
- package/dist/ts3.9/server/framework-preset-react.d.ts +0 -6
- package/dist/ts3.9/server/index.d.ts +0 -1
- package/dist/ts3.9/server/options.d.ts +0 -3
- package/dist/ts3.9/server/preset.d.ts +0 -3
- package/preset.js +0 -1
- package/standalone.js +0 -8
- package/types/index.ts +0 -19
- package/types-6-0.d.ts +0 -1
- package/types-7-0.d.ts +0 -1
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { InspectionType } from '../inspection';
|
|
2
|
-
export function getPrettyIdentifier(inferredType) {
|
|
3
|
-
var type = inferredType.type,
|
|
4
|
-
identifier = inferredType.identifier;
|
|
5
|
-
|
|
6
|
-
switch (type) {
|
|
7
|
-
case InspectionType.FUNCTION:
|
|
8
|
-
return getPrettyFuncIdentifier(identifier, inferredType.hasParams);
|
|
9
|
-
|
|
10
|
-
case InspectionType.ELEMENT:
|
|
11
|
-
return getPrettyElementIdentifier(identifier);
|
|
12
|
-
|
|
13
|
-
default:
|
|
14
|
-
return identifier;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
export function getPrettyFuncIdentifier(identifier, hasArguments) {
|
|
18
|
-
return hasArguments ? "".concat(identifier, "( ... )") : "".concat(identifier, "()");
|
|
19
|
-
}
|
|
20
|
-
export function getPrettyElementIdentifier(identifier) {
|
|
21
|
-
return "<".concat(identifier, " />");
|
|
22
|
-
}
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import "core-js/modules/es.object.assign.js";
|
|
2
|
-
import "core-js/modules/es.string.ends-with.js";
|
|
3
|
-
import "core-js/modules/es.array.slice.js";
|
|
4
|
-
import "core-js/modules/es.string.starts-with.js";
|
|
5
|
-
import "core-js/modules/es.regexp.exec.js";
|
|
6
|
-
import "core-js/modules/es.string.replace.js";
|
|
7
|
-
import { generate } from 'escodegen';
|
|
8
|
-
import dedent from 'ts-dedent';
|
|
9
|
-
var BASIC_OPTIONS = {
|
|
10
|
-
format: {
|
|
11
|
-
indent: {
|
|
12
|
-
style: ' '
|
|
13
|
-
},
|
|
14
|
-
semicolons: false
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
var COMPACT_OPTIONS = Object.assign({}, BASIC_OPTIONS, {
|
|
18
|
-
format: {
|
|
19
|
-
newline: ''
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
var PRETTY_OPTIONS = Object.assign({}, BASIC_OPTIONS);
|
|
23
|
-
export function generateCode(ast) {
|
|
24
|
-
var compact = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
25
|
-
return generate(ast, compact ? COMPACT_OPTIONS : PRETTY_OPTIONS);
|
|
26
|
-
}
|
|
27
|
-
export function generateObjectCode(ast) {
|
|
28
|
-
var compact = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
29
|
-
return !compact ? generateCode(ast) : generateCompactObjectCode(ast);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function generateCompactObjectCode(ast) {
|
|
33
|
-
var result = generateCode(ast, true); // Cannot get escodegen to add a space before the last } with the compact mode settings.
|
|
34
|
-
// Fix it until a better solution is found.
|
|
35
|
-
|
|
36
|
-
if (!result.endsWith(' }')) {
|
|
37
|
-
result = "".concat(result.slice(0, -1), " }");
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
return result;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export function generateArrayCode(ast) {
|
|
44
|
-
var compact = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
45
|
-
return !compact ? generateMultilineArrayCode(ast) : generateCompactArrayCode(ast);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function generateMultilineArrayCode(ast) {
|
|
49
|
-
var result = generateCode(ast); // escodegen add extra spacing before the closing bracket of a multiple line array with a nested object.
|
|
50
|
-
// Fix it until a better solution is found.
|
|
51
|
-
|
|
52
|
-
if (result.endsWith(' }]')) {
|
|
53
|
-
result = dedent(result);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
return result;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
function generateCompactArrayCode(ast) {
|
|
60
|
-
var result = generateCode(ast, true); // escodegen add extra an extra before the opening bracket of a compact array that contains primitive values.
|
|
61
|
-
// Fix it until a better solution is found.
|
|
62
|
-
|
|
63
|
-
if (result.startsWith('[ ')) {
|
|
64
|
-
result = result.replace('[ ', '[');
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
return result;
|
|
68
|
-
}
|
|
@@ -1,213 +0,0 @@
|
|
|
1
|
-
import "core-js/modules/es.object.assign.js";
|
|
2
|
-
import "core-js/modules/es.function.name.js";
|
|
3
|
-
import "core-js/modules/es.array.filter.js";
|
|
4
|
-
import "core-js/modules/es.object.to-string.js";
|
|
5
|
-
import { Parser } from 'acorn';
|
|
6
|
-
import jsx from 'acorn-jsx';
|
|
7
|
-
import * as acornWalk from 'acorn-walk';
|
|
8
|
-
import { InspectionType } from './types';
|
|
9
|
-
var ACORN_WALK_VISITORS = Object.assign({}, acornWalk.base, {
|
|
10
|
-
JSXElement: function JSXElement() {}
|
|
11
|
-
});
|
|
12
|
-
var acornParser = Parser.extend(jsx()); // Cannot use "estree.Identifier" type because this function also support "JSXIdentifier".
|
|
13
|
-
|
|
14
|
-
function extractIdentifierName(identifierNode) {
|
|
15
|
-
return identifierNode != null ? identifierNode.name : null;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function filterAncestors(ancestors) {
|
|
19
|
-
return ancestors.filter(function (x) {
|
|
20
|
-
return x.type === 'ObjectExpression' || x.type === 'ArrayExpression';
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function calculateNodeDepth(node) {
|
|
25
|
-
var depths = [];
|
|
26
|
-
acornWalk.ancestor( // @ts-ignore
|
|
27
|
-
node, {
|
|
28
|
-
ObjectExpression: function ObjectExpression(_, ancestors) {
|
|
29
|
-
depths.push(filterAncestors(ancestors).length);
|
|
30
|
-
},
|
|
31
|
-
ArrayExpression: function ArrayExpression(_, ancestors) {
|
|
32
|
-
depths.push(filterAncestors(ancestors).length);
|
|
33
|
-
}
|
|
34
|
-
}, ACORN_WALK_VISITORS);
|
|
35
|
-
return Math.max.apply(Math, depths);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function parseIdentifier(identifierNode) {
|
|
39
|
-
return {
|
|
40
|
-
inferredType: {
|
|
41
|
-
type: InspectionType.IDENTIFIER,
|
|
42
|
-
identifier: extractIdentifierName(identifierNode)
|
|
43
|
-
},
|
|
44
|
-
ast: identifierNode
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function parseLiteral(literalNode) {
|
|
49
|
-
return {
|
|
50
|
-
inferredType: {
|
|
51
|
-
type: InspectionType.LITERAL
|
|
52
|
-
},
|
|
53
|
-
ast: literalNode
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
function parseFunction(funcNode) {
|
|
58
|
-
var innerJsxElementNode; // If there is at least a JSXElement in the body of the function, then it's a React component.
|
|
59
|
-
|
|
60
|
-
acornWalk.simple( // @ts-ignore
|
|
61
|
-
funcNode.body, {
|
|
62
|
-
JSXElement: function JSXElement(node) {
|
|
63
|
-
innerJsxElementNode = node;
|
|
64
|
-
}
|
|
65
|
-
}, ACORN_WALK_VISITORS);
|
|
66
|
-
var isJsx = innerJsxElementNode != null;
|
|
67
|
-
var inferredType = {
|
|
68
|
-
type: isJsx ? InspectionType.ELEMENT : InspectionType.FUNCTION,
|
|
69
|
-
params: funcNode.params,
|
|
70
|
-
hasParams: funcNode.params.length !== 0
|
|
71
|
-
};
|
|
72
|
-
var identifierName = extractIdentifierName(funcNode.id);
|
|
73
|
-
|
|
74
|
-
if (identifierName != null) {
|
|
75
|
-
inferredType.identifier = identifierName;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
return {
|
|
79
|
-
inferredType: inferredType,
|
|
80
|
-
ast: funcNode
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
function parseClass(classNode) {
|
|
85
|
-
var innerJsxElementNode; // If there is at least a JSXElement in the body of the class, then it's a React component.
|
|
86
|
-
|
|
87
|
-
acornWalk.simple( // @ts-ignore
|
|
88
|
-
classNode.body, {
|
|
89
|
-
JSXElement: function JSXElement(node) {
|
|
90
|
-
innerJsxElementNode = node;
|
|
91
|
-
}
|
|
92
|
-
}, ACORN_WALK_VISITORS);
|
|
93
|
-
var inferredType = {
|
|
94
|
-
type: innerJsxElementNode != null ? InspectionType.ELEMENT : InspectionType.CLASS,
|
|
95
|
-
identifier: extractIdentifierName(classNode.id)
|
|
96
|
-
};
|
|
97
|
-
return {
|
|
98
|
-
inferredType: inferredType,
|
|
99
|
-
ast: classNode
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
function parseJsxElement(jsxElementNode) {
|
|
104
|
-
var inferredType = {
|
|
105
|
-
type: InspectionType.ELEMENT
|
|
106
|
-
};
|
|
107
|
-
var identifierName = extractIdentifierName(jsxElementNode.openingElement.name);
|
|
108
|
-
|
|
109
|
-
if (identifierName != null) {
|
|
110
|
-
inferredType.identifier = identifierName;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
return {
|
|
114
|
-
inferredType: inferredType,
|
|
115
|
-
ast: jsxElementNode
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
function parseCall(callNode) {
|
|
120
|
-
var identifierNode = callNode.callee.type === 'MemberExpression' ? callNode.callee.property : callNode.callee;
|
|
121
|
-
var identifierName = extractIdentifierName(identifierNode);
|
|
122
|
-
|
|
123
|
-
if (identifierName === 'shape') {
|
|
124
|
-
return parseObject(callNode.arguments[0]);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
return null;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
function parseObject(objectNode) {
|
|
131
|
-
return {
|
|
132
|
-
inferredType: {
|
|
133
|
-
type: InspectionType.OBJECT,
|
|
134
|
-
depth: calculateNodeDepth(objectNode)
|
|
135
|
-
},
|
|
136
|
-
ast: objectNode
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
function parseArray(arrayNode) {
|
|
141
|
-
return {
|
|
142
|
-
inferredType: {
|
|
143
|
-
type: InspectionType.ARRAY,
|
|
144
|
-
depth: calculateNodeDepth(arrayNode)
|
|
145
|
-
},
|
|
146
|
-
ast: arrayNode
|
|
147
|
-
};
|
|
148
|
-
} // Cannot set "expression" type to "estree.Expression" because the type doesn't include JSX.
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
function parseExpression(expression) {
|
|
152
|
-
switch (expression.type) {
|
|
153
|
-
case 'Identifier':
|
|
154
|
-
return parseIdentifier(expression);
|
|
155
|
-
|
|
156
|
-
case 'Literal':
|
|
157
|
-
return parseLiteral(expression);
|
|
158
|
-
|
|
159
|
-
case 'FunctionExpression':
|
|
160
|
-
case 'ArrowFunctionExpression':
|
|
161
|
-
return parseFunction(expression);
|
|
162
|
-
|
|
163
|
-
case 'ClassExpression':
|
|
164
|
-
return parseClass(expression);
|
|
165
|
-
|
|
166
|
-
case 'JSXElement':
|
|
167
|
-
return parseJsxElement(expression);
|
|
168
|
-
|
|
169
|
-
case 'CallExpression':
|
|
170
|
-
return parseCall(expression);
|
|
171
|
-
|
|
172
|
-
case 'ObjectExpression':
|
|
173
|
-
return parseObject(expression);
|
|
174
|
-
|
|
175
|
-
case 'ArrayExpression':
|
|
176
|
-
return parseArray(expression);
|
|
177
|
-
|
|
178
|
-
default:
|
|
179
|
-
return null;
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
export function parse(value) {
|
|
184
|
-
var ast = acornParser.parse("(".concat(value, ")"));
|
|
185
|
-
var parsingResult = {
|
|
186
|
-
inferredType: {
|
|
187
|
-
type: InspectionType.UNKNOWN
|
|
188
|
-
},
|
|
189
|
-
ast: ast
|
|
190
|
-
};
|
|
191
|
-
|
|
192
|
-
if (ast.body[0] != null) {
|
|
193
|
-
var rootNode = ast.body[0];
|
|
194
|
-
|
|
195
|
-
switch (rootNode.type) {
|
|
196
|
-
case 'ExpressionStatement':
|
|
197
|
-
{
|
|
198
|
-
var expressionResult = parseExpression(rootNode.expression);
|
|
199
|
-
|
|
200
|
-
if (expressionResult != null) {
|
|
201
|
-
parsingResult = expressionResult;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
break;
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
default:
|
|
208
|
-
break;
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
return parsingResult;
|
|
213
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import "core-js/modules/es.object.assign.js";
|
|
2
|
-
import { parse } from './acornParser';
|
|
3
|
-
import { InspectionType } from './types';
|
|
4
|
-
export function inspectValue(value) {
|
|
5
|
-
try {
|
|
6
|
-
var parsingResult = parse(value);
|
|
7
|
-
return Object.assign({}, parsingResult);
|
|
8
|
-
} catch (e) {// do nothing.
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
return {
|
|
12
|
-
inferredType: {
|
|
13
|
-
type: InspectionType.UNKNOWN
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export var InspectionType;
|
|
2
|
-
|
|
3
|
-
(function (InspectionType) {
|
|
4
|
-
InspectionType["IDENTIFIER"] = "Identifier";
|
|
5
|
-
InspectionType["LITERAL"] = "Literal";
|
|
6
|
-
InspectionType["OBJECT"] = "Object";
|
|
7
|
-
InspectionType["ARRAY"] = "Array";
|
|
8
|
-
InspectionType["FUNCTION"] = "Function";
|
|
9
|
-
InspectionType["CLASS"] = "Class";
|
|
10
|
-
InspectionType["ELEMENT"] = "Element";
|
|
11
|
-
InspectionType["UNKNOWN"] = "Unknown";
|
|
12
|
-
})(InspectionType || (InspectionType = {}));
|