Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Typescript-specific nodes #80

Merged
merged 1 commit into from
May 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions __tests__/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,5 @@ export function extractProp(code, prop = 'foo') {
const { attributes: props } = node;
return getProp(props, prop);
}

export const describeIfNotBabylon = fallbackToBabylon ? describe.skip : describe;
36 changes: 35 additions & 1 deletion __tests__/src/getPropLiteralValue-test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-env mocha */
/* eslint no-template-curly-in-string: 0 */
import assert from 'assert';
import { extractProp } from '../helper';
import { extractProp, describeIfNotBabylon, changePlugins } from '../helper';
import { getLiteralPropValue } from '../../src/getPropValue';

describe('getLiteralPropValue', () => {
Expand Down Expand Up @@ -465,4 +465,38 @@ describe('getLiteralPropValue', () => {
assert.deepEqual(expected, actual);
});
});

describeIfNotBabylon('Typescript', () => {
beforeEach(() => {
changePlugins(pls => [...pls, 'typescript']);
});

it('should return string representation of variable identifier wrapped in a Typescript non-null assertion', () => {
const prop = extractProp('<div foo={bar!} />');

const expected = null;
const actual = getLiteralPropValue(prop);

assert.equal(expected, actual);
});

it('should return string representation of variable identifier wrapped in a deep Typescript non-null assertion', () => {
const prop = extractProp('<div foo={(bar!)!} />');

const expected = null;
const actual = getLiteralPropValue(prop);

assert.equal(expected, actual);
});

it('should return string representation of variable identifier wrapped in a Typescript type coercion', () => {
changePlugins(pls => [...pls, 'typescript']);
const prop = extractProp('<div foo={bar as any} />');

const expected = null;
const actual = getLiteralPropValue(prop);

assert.equal(expected, actual);
});
});
});
4 changes: 1 addition & 3 deletions __tests__/src/getPropValue-test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
/* eslint-env mocha */
/* eslint no-template-curly-in-string: 0 */
import assert from 'assert';
import { extractProp, changePlugins, fallbackToBabylon } from '../helper';
import { extractProp, changePlugins, fallbackToBabylon, describeIfNotBabylon } from '../helper';
import getPropValue from '../../src/getPropValue';

const describeIfNotBabylon = fallbackToBabylon ? describe.skip : describe;

describe('getPropValue', () => {
it('should export a function', () => {
const expected = 'function';
Expand Down
2 changes: 2 additions & 0 deletions src/values/expressions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ const LITERAL_TYPES = Object.assign({}, TYPES, {
},
BindExpression: noop,
SpreadElement: noop,
TSNonNullExpression: noop,
TSAsExpression: noop,
});

/**
Expand Down