|
Last change
on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 2 weeks ago |
|
Fix frontend appearance
|
-
Property mode
set to
100644
|
|
File size:
1.0 KB
|
| Line | |
|---|
| 1 | /**
|
|---|
| 2 | * @flow
|
|---|
| 3 | */
|
|---|
| 4 |
|
|---|
| 5 | import toAST from 'to-ast'; // eslint-disable-line import/no-extraneous-dependencies
|
|---|
| 6 | import JSXExpressionContainerMock from './JSXExpressionContainerMock';
|
|---|
| 7 |
|
|---|
| 8 | export type JSXAttributeMockType = {
|
|---|
| 9 | type: 'JSXAttribute',
|
|---|
| 10 | name: {
|
|---|
| 11 | type: 'JSXIdentifier',
|
|---|
| 12 | name: string,
|
|---|
| 13 | },
|
|---|
| 14 | value: mixed,
|
|---|
| 15 | };
|
|---|
| 16 |
|
|---|
| 17 | export default function JSXAttributeMock(prop: string, value: mixed, isExpressionContainer?: boolean = false): JSXAttributeMockType {
|
|---|
| 18 | let astValue;
|
|---|
| 19 | if (value && value.type !== undefined) {
|
|---|
| 20 | astValue = value;
|
|---|
| 21 | } else {
|
|---|
| 22 | astValue = toAST(value);
|
|---|
| 23 | }
|
|---|
| 24 | let attributeValue = astValue;
|
|---|
| 25 | if (isExpressionContainer || astValue.type !== 'Literal') {
|
|---|
| 26 | attributeValue = JSXExpressionContainerMock(astValue);
|
|---|
| 27 | } else if (attributeValue.type === 'Literal' && !('raw' in (attributeValue: any))) {
|
|---|
| 28 | (attributeValue: any).raw = JSON.stringify((attributeValue: any).value);
|
|---|
| 29 | }
|
|---|
| 30 |
|
|---|
| 31 | return {
|
|---|
| 32 | type: 'JSXAttribute',
|
|---|
| 33 | name: {
|
|---|
| 34 | type: 'JSXIdentifier',
|
|---|
| 35 | name: prop,
|
|---|
| 36 | },
|
|---|
| 37 | value: attributeValue,
|
|---|
| 38 | };
|
|---|
| 39 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.