Skip to content

Commit

Permalink
fix(babel-plugin-export-metadata): just define pro non-primitive types
Browse files Browse the repository at this point in the history
  • Loading branch information
pedronauck committed Feb 27, 2019
1 parent 37b73c6 commit ed78a13
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 10 deletions.
14 changes: 9 additions & 5 deletions other-packages/babel-plugin-export-metadata/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ const { default: template } = require('@babel/template')
const { get } = require('lodash')

const buildFileMeta = template(`
if (typeof ID !== 'undefined') {
ID.__filemeta = {
name: NAME,
filename: FILENAME
};
if (ID === Object(ID)) {
Object.defineProperty(ID, '__filemeta', {
enumerable: true,
configurable: true,
value: {
name: NAME,
filename: FILENAME
}
});
}
`)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`works 1`] = `
"const foo = () => 'foo';
export const bar = () => 'bar';
if (bar === Object(bar)) {
Object.defineProperty(bar, '__filemeta', {
writable: false,
value: {
name: \\"bar\\",
filename: \\"/Volumes/Projects/dev/docz/docz/other-packages/babel-plugin-export-metadata/tests/fixtures/example.js\\"
}
});
}
if (bar === Object(bar)) {
Object.defineProperty(bar, '__filemeta', {
writable: false,
value: {
name: \\"bar\\",
filename: \\"/Volumes/Projects/dev/docz/docz/other-packages/babel-plugin-export-metadata/tests/fixtures/example.js\\"
}
});
}
const obj = {
foo: () => 'foo'
/**
* Some description
*/
};
function get(object, path) {
return object[path];
}
export function getOther(object, path) {
return object[path];
}
if (getOther === Object(getOther)) {
Object.defineProperty(getOther, '__filemeta', {
writable: false,
value: {
name: \\"getOther\\",
filename: \\"/Volumes/Projects/dev/docz/docz/other-packages/babel-plugin-export-metadata/tests/fixtures/example.js\\"
}
});
}
const obj2 = {
get: () => null
/**
* Some description
*/
};
class Abc {
/**
* Some description
*/
method() {
return null;
}
}
export const component = styled.div\`
background: red;
\`;
if (component === Object(component)) {
Object.defineProperty(component, '__filemeta', {
writable: false,
value: {
name: \\"component\\",
filename: \\"/Volumes/Projects/dev/docz/docz/other-packages/babel-plugin-export-metadata/tests/fixtures/example.js\\"
}
});
}
export class Abcd {
/**
* Some description
*/
method() {
return null;
}
}
if (Abcd === Object(Abcd)) {
Object.defineProperty(Abcd, '__filemeta', {
writable: false,
value: {
name: \\"Abcd\\",
filename: \\"/Volumes/Projects/dev/docz/docz/other-packages/babel-plugin-export-metadata/tests/fixtures/example.js\\"
}
});
}
const obj3 = {
method: class Abcd {
method() {
return null;
}
}
};
const log = fn => fn(1);
log(id => console.log(id));
export default (() => 'other');"
`;
10 changes: 5 additions & 5 deletions other-packages/babel-plugin-export-metadata/tests/index.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { transformSync } from '@babel/core'
import * as fs from 'fs'
import * as path from 'path'
import plugin from '../src'
const { transformSync } = require('@babel/core')
const fs = require('fs')
const path = require('path')
const plugin = require('../src')

const fixture = path.resolve('./tests/fixtures/example.js')
const code = fs.readFileSync(fixture).toString()
Expand All @@ -12,5 +12,5 @@ it('works', () => {
filename: fixture,
})

expect(result!.code).toMatchSnapshot()
expect(result.code).toMatchSnapshot()
})

0 comments on commit ed78a13

Please sign in to comment.