Skip to content
This repository was archived by the owner on Jan 24, 2025. It is now read-only.

Commit 9067ffb

Browse files
authored
fix(babel-plugin-export-metadata): fix hasOwnProperty method call (#1581)
1 parent fadb6dd commit 9067ffb

File tree

2 files changed

+27
-21
lines changed

2 files changed

+27
-21
lines changed

other-packages/babel-plugin-export-metadata/src/index.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@ const { default: template } = require('@babel/template')
33
const { get } = require('lodash')
44

55
const buildFileMeta = template(`
6-
if (typeof ID !== 'undefined' && ID && ID === Object(ID) && Object.isExtensible(ID) && !ID.hasOwnProperty('__filemeta')) {
6+
if (
7+
typeof ID !== 'undefined' &&
8+
ID &&
9+
ID === Object(ID) &&
10+
Object.isExtensible(ID) &&
11+
!Object.prototype.hasOwnProperty.call(ID, '__filemeta')
12+
) {
713
Object.defineProperty(ID, '__filemeta', {
814
configurable: true,
915
value: {

other-packages/babel-plugin-export-metadata/tests/__snapshots__/index.test.js.snap

+20-20
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ let bar5 = () => {};
88
99
export default [foo5, bar5];
1010
11-
if (typeof bar5 !== 'undefined' && bar5 && bar5 === Object(bar5) && Object.isExtensible(bar5) && !bar5.hasOwnProperty('__filemeta')) {
11+
if (typeof bar5 !== 'undefined' && bar5 && bar5 === Object(bar5) && Object.isExtensible(bar5) && !Object.prototype.hasOwnProperty.call(bar5, '__filemeta')) {
1212
Object.defineProperty(bar5, '__filemeta', {
1313
configurable: true,
1414
value: {
@@ -18,7 +18,7 @@ if (typeof bar5 !== 'undefined' && bar5 && bar5 === Object(bar5) && Object.isExt
1818
});
1919
}
2020
21-
if (typeof foo5 !== 'undefined' && foo5 && foo5 === Object(foo5) && Object.isExtensible(foo5) && !foo5.hasOwnProperty('__filemeta')) {
21+
if (typeof foo5 !== 'undefined' && foo5 && foo5 === Object(foo5) && Object.isExtensible(foo5) && !Object.prototype.hasOwnProperty.call(foo5, '__filemeta')) {
2222
Object.defineProperty(foo5, '__filemeta', {
2323
configurable: true,
2424
value: {
@@ -37,7 +37,7 @@ const __DOCZ_DUMMY_EXPORT_DEFAULT = foo(5);
3737
3838
export default __DOCZ_DUMMY_EXPORT_DEFAULT;
3939
40-
if (typeof __DOCZ_DUMMY_EXPORT_DEFAULT !== 'undefined' && __DOCZ_DUMMY_EXPORT_DEFAULT && __DOCZ_DUMMY_EXPORT_DEFAULT === Object(__DOCZ_DUMMY_EXPORT_DEFAULT) && Object.isExtensible(__DOCZ_DUMMY_EXPORT_DEFAULT) && !__DOCZ_DUMMY_EXPORT_DEFAULT.hasOwnProperty('__filemeta')) {
40+
if (typeof __DOCZ_DUMMY_EXPORT_DEFAULT !== 'undefined' && __DOCZ_DUMMY_EXPORT_DEFAULT && __DOCZ_DUMMY_EXPORT_DEFAULT === Object(__DOCZ_DUMMY_EXPORT_DEFAULT) && Object.isExtensible(__DOCZ_DUMMY_EXPORT_DEFAULT) && !Object.prototype.hasOwnProperty.call(__DOCZ_DUMMY_EXPORT_DEFAULT, '__filemeta')) {
4141
Object.defineProperty(__DOCZ_DUMMY_EXPORT_DEFAULT, '__filemeta', {
4242
configurable: true,
4343
value: {
@@ -52,7 +52,7 @@ exports[`export-metadata export default works with Class declaration 1`] = `
5252
"/* ExportDefaultDeclaration with Class declaration */
5353
export default class Bar6 {}
5454
55-
if (typeof Bar6 !== 'undefined' && Bar6 && Bar6 === Object(Bar6) && Object.isExtensible(Bar6) && !Bar6.hasOwnProperty('__filemeta')) {
55+
if (typeof Bar6 !== 'undefined' && Bar6 && Bar6 === Object(Bar6) && Object.isExtensible(Bar6) && !Object.prototype.hasOwnProperty.call(Bar6, '__filemeta')) {
5656
Object.defineProperty(Bar6, '__filemeta', {
5757
configurable: true,
5858
value: {
@@ -67,7 +67,7 @@ exports[`export-metadata export default works with Function declaration 1`] = `
6767
"/* ExportDefaultDeclaration with Function declaration */
6868
export default function foo6() {}
6969
70-
if (typeof foo6 !== 'undefined' && foo6 && foo6 === Object(foo6) && Object.isExtensible(foo6) && !foo6.hasOwnProperty('__filemeta')) {
70+
if (typeof foo6 !== 'undefined' && foo6 && foo6 === Object(foo6) && Object.isExtensible(foo6) && !Object.prototype.hasOwnProperty.call(foo6, '__filemeta')) {
7171
Object.defineProperty(foo6, '__filemeta', {
7272
configurable: true,
7373
value: {
@@ -83,7 +83,7 @@ exports[`export-metadata export default works with Identifier 1`] = `
8383
let foo3 = 5;
8484
export default foo3;
8585
86-
if (typeof foo3 !== 'undefined' && foo3 && foo3 === Object(foo3) && Object.isExtensible(foo3) && !foo3.hasOwnProperty('__filemeta')) {
86+
if (typeof foo3 !== 'undefined' && foo3 && foo3 === Object(foo3) && Object.isExtensible(foo3) && !Object.prototype.hasOwnProperty.call(foo3, '__filemeta')) {
8787
Object.defineProperty(foo3, '__filemeta', {
8888
configurable: true,
8989
value: {
@@ -101,7 +101,7 @@ export default {
101101
bar4: () => {}
102102
};
103103
104-
if (typeof bar4 !== 'undefined' && bar4 && bar4 === Object(bar4) && Object.isExtensible(bar4) && !bar4.hasOwnProperty('__filemeta')) {
104+
if (typeof bar4 !== 'undefined' && bar4 && bar4 === Object(bar4) && Object.isExtensible(bar4) && !Object.prototype.hasOwnProperty.call(bar4, '__filemeta')) {
105105
Object.defineProperty(bar4, '__filemeta', {
106106
configurable: true,
107107
value: {
@@ -111,7 +111,7 @@ if (typeof bar4 !== 'undefined' && bar4 && bar4 === Object(bar4) && Object.isExt
111111
});
112112
}
113113
114-
if (typeof foo4 !== 'undefined' && foo4 && foo4 === Object(foo4) && Object.isExtensible(foo4) && !foo4.hasOwnProperty('__filemeta')) {
114+
if (typeof foo4 !== 'undefined' && foo4 && foo4 === Object(foo4) && Object.isExtensible(foo4) && !Object.prototype.hasOwnProperty.call(foo4, '__filemeta')) {
115115
Object.defineProperty(foo4, '__filemeta', {
116116
configurable: true,
117117
value: {
@@ -132,7 +132,7 @@ let baz = 'baz';
132132
export { foo as default, bar as foobar, baz };
133133
/* ExportNamedDeclaration with Variable declarations */
134134
135-
if (typeof baz !== 'undefined' && baz && baz === Object(baz) && Object.isExtensible(baz) && !baz.hasOwnProperty('__filemeta')) {
135+
if (typeof baz !== 'undefined' && baz && baz === Object(baz) && Object.isExtensible(baz) && !Object.prototype.hasOwnProperty.call(baz, '__filemeta')) {
136136
Object.defineProperty(baz, '__filemeta', {
137137
configurable: true,
138138
value: {
@@ -142,7 +142,7 @@ if (typeof baz !== 'undefined' && baz && baz === Object(baz) && Object.isExtensi
142142
});
143143
}
144144
145-
if (typeof bar !== 'undefined' && bar && bar === Object(bar) && Object.isExtensible(bar) && !bar.hasOwnProperty('__filemeta')) {
145+
if (typeof bar !== 'undefined' && bar && bar === Object(bar) && Object.isExtensible(bar) && !Object.prototype.hasOwnProperty.call(bar, '__filemeta')) {
146146
Object.defineProperty(bar, '__filemeta', {
147147
configurable: true,
148148
value: {
@@ -152,7 +152,7 @@ if (typeof bar !== 'undefined' && bar && bar === Object(bar) && Object.isExtensi
152152
});
153153
}
154154
155-
if (typeof foo !== 'undefined' && foo && foo === Object(foo) && Object.isExtensible(foo) && !foo.hasOwnProperty('__filemeta')) {
155+
if (typeof foo !== 'undefined' && foo && foo === Object(foo) && Object.isExtensible(foo) && !Object.prototype.hasOwnProperty.call(foo, '__filemeta')) {
156156
Object.defineProperty(foo, '__filemeta', {
157157
configurable: true,
158158
value: {
@@ -166,7 +166,7 @@ export let foo1 = 5,
166166
bar1 = () => {};
167167
/* ExportNamedDeclaration with Function and Class declarations */
168168
169-
if (typeof bar1 !== 'undefined' && bar1 && bar1 === Object(bar1) && Object.isExtensible(bar1) && !bar1.hasOwnProperty('__filemeta')) {
169+
if (typeof bar1 !== 'undefined' && bar1 && bar1 === Object(bar1) && Object.isExtensible(bar1) && !Object.prototype.hasOwnProperty.call(bar1, '__filemeta')) {
170170
Object.defineProperty(bar1, '__filemeta', {
171171
configurable: true,
172172
value: {
@@ -176,7 +176,7 @@ if (typeof bar1 !== 'undefined' && bar1 && bar1 === Object(bar1) && Object.isExt
176176
});
177177
}
178178
179-
if (typeof foo1 !== 'undefined' && foo1 && foo1 === Object(foo1) && Object.isExtensible(foo1) && !foo1.hasOwnProperty('__filemeta')) {
179+
if (typeof foo1 !== 'undefined' && foo1 && foo1 === Object(foo1) && Object.isExtensible(foo1) && !Object.prototype.hasOwnProperty.call(foo1, '__filemeta')) {
180180
Object.defineProperty(foo1, '__filemeta', {
181181
configurable: true,
182182
value: {
@@ -188,7 +188,7 @@ if (typeof foo1 !== 'undefined' && foo1 && foo1 === Object(foo1) && Object.isExt
188188
189189
export function foo2() {}
190190
191-
if (typeof foo2 !== 'undefined' && foo2 && foo2 === Object(foo2) && Object.isExtensible(foo2) && !foo2.hasOwnProperty('__filemeta')) {
191+
if (typeof foo2 !== 'undefined' && foo2 && foo2 === Object(foo2) && Object.isExtensible(foo2) && !Object.prototype.hasOwnProperty.call(foo2, '__filemeta')) {
192192
Object.defineProperty(foo2, '__filemeta', {
193193
configurable: true,
194194
value: {
@@ -200,7 +200,7 @@ if (typeof foo2 !== 'undefined' && foo2 && foo2 === Object(foo2) && Object.isExt
200200
201201
export class Bar2 {}
202202
203-
if (typeof Bar2 !== 'undefined' && Bar2 && Bar2 === Object(Bar2) && Object.isExtensible(Bar2) && !Bar2.hasOwnProperty('__filemeta')) {
203+
if (typeof Bar2 !== 'undefined' && Bar2 && Bar2 === Object(Bar2) && Object.isExtensible(Bar2) && !Object.prototype.hasOwnProperty.call(Bar2, '__filemeta')) {
204204
Object.defineProperty(Bar2, '__filemeta', {
205205
configurable: true,
206206
value: {
@@ -216,7 +216,7 @@ exports[`export-metadata re-export re export default 1`] = `
216216
import __DOCZ_DUMMY_EXPORT_DEFAULT from \\"../assets/a\\";
217217
export default __DOCZ_DUMMY_EXPORT_DEFAULT;
218218
219-
if (typeof __DOCZ_DUMMY_EXPORT_DEFAULT !== 'undefined' && __DOCZ_DUMMY_EXPORT_DEFAULT && __DOCZ_DUMMY_EXPORT_DEFAULT === Object(__DOCZ_DUMMY_EXPORT_DEFAULT) && Object.isExtensible(__DOCZ_DUMMY_EXPORT_DEFAULT) && !__DOCZ_DUMMY_EXPORT_DEFAULT.hasOwnProperty('__filemeta')) {
219+
if (typeof __DOCZ_DUMMY_EXPORT_DEFAULT !== 'undefined' && __DOCZ_DUMMY_EXPORT_DEFAULT && __DOCZ_DUMMY_EXPORT_DEFAULT === Object(__DOCZ_DUMMY_EXPORT_DEFAULT) && Object.isExtensible(__DOCZ_DUMMY_EXPORT_DEFAULT) && !Object.prototype.hasOwnProperty.call(__DOCZ_DUMMY_EXPORT_DEFAULT, '__filemeta')) {
220220
Object.defineProperty(__DOCZ_DUMMY_EXPORT_DEFAULT, '__filemeta', {
221221
configurable: true,
222222
value: {
@@ -231,7 +231,7 @@ exports[`export-metadata re-export re export default to name 1`] = `
231231
"/* Re-export */
232232
export { default as aDefault } from '../assets/a';
233233
234-
if (typeof aDefault !== 'undefined' && aDefault && aDefault === Object(aDefault) && Object.isExtensible(aDefault) && !aDefault.hasOwnProperty('__filemeta')) {
234+
if (typeof aDefault !== 'undefined' && aDefault && aDefault === Object(aDefault) && Object.isExtensible(aDefault) && !Object.prototype.hasOwnProperty.call(aDefault, '__filemeta')) {
235235
Object.defineProperty(aDefault, '__filemeta', {
236236
configurable: true,
237237
value: {
@@ -246,7 +246,7 @@ exports[`export-metadata re-export re export name 1`] = `
246246
"/* Re-export */
247247
export { a } from '../assets/a';
248248
249-
if (typeof a !== 'undefined' && a && a === Object(a) && Object.isExtensible(a) && !a.hasOwnProperty('__filemeta')) {
249+
if (typeof a !== 'undefined' && a && a === Object(a) && Object.isExtensible(a) && !Object.prototype.hasOwnProperty.call(a, '__filemeta')) {
250250
Object.defineProperty(a, '__filemeta', {
251251
configurable: true,
252252
value: {
@@ -262,7 +262,7 @@ exports[`export-metadata re-export re export name to default 1`] = `
262262
import a from \\"../assets/a\\";
263263
export default a;
264264
265-
if (typeof a !== 'undefined' && a && a === Object(a) && Object.isExtensible(a) && !a.hasOwnProperty('__filemeta')) {
265+
if (typeof a !== 'undefined' && a && a === Object(a) && Object.isExtensible(a) && !Object.prototype.hasOwnProperty.call(a, '__filemeta')) {
266266
Object.defineProperty(a, '__filemeta', {
267267
configurable: true,
268268
value: {
@@ -277,7 +277,7 @@ exports[`export-metadata re-export re export name to name 1`] = `
277277
"/* Re-export */
278278
export { a as aa } from '../assets/a';
279279
280-
if (typeof aa !== 'undefined' && aa && aa === Object(aa) && Object.isExtensible(aa) && !aa.hasOwnProperty('__filemeta')) {
280+
if (typeof aa !== 'undefined' && aa && aa === Object(aa) && Object.isExtensible(aa) && !Object.prototype.hasOwnProperty.call(aa, '__filemeta')) {
281281
Object.defineProperty(aa, '__filemeta', {
282282
configurable: true,
283283
value: {

0 commit comments

Comments
 (0)