mirror of
https://github.com/swc-project/swc.git
synced 2024-12-30 00:52:29 +03:00
bbaf619f63
swc_bundler: - [x] Fix wrapped esms. (denoland/deno#9307) - [x] Make test secure.
34 lines
1022 B
TypeScript
34 lines
1022 B
TypeScript
// Loaded from https://deno.land/std@0.81.0/_util/has_own_property.ts
|
|
|
|
|
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
|
|
|
/**
|
|
* Determines whether an object has a property with the specified name.
|
|
* Avoid calling prototype builtin `hasOwnProperty` for two reasons:
|
|
*
|
|
* 1. `hasOwnProperty` is defined on the object as something else:
|
|
*
|
|
* const options = {
|
|
* ending: 'utf8',
|
|
* hasOwnProperty: 'foo'
|
|
* };
|
|
* options.hasOwnProperty('ending') // throws a TypeError
|
|
*
|
|
* 2. The object doesn't inherit from `Object.prototype`:
|
|
*
|
|
* const options = Object.create(null);
|
|
* options.ending = 'utf8';
|
|
* options.hasOwnProperty('ending'); // throws a TypeError
|
|
*
|
|
* @param obj A Object.
|
|
* @param v A property name.
|
|
* @see https://eslint.org/docs/rules/no-prototype-builtins
|
|
*/
|
|
export function hasOwnProperty<T>(obj: T, v: PropertyKey): boolean {
|
|
if (obj == null) {
|
|
return false;
|
|
}
|
|
return Object.prototype.hasOwnProperty.call(obj, v);
|
|
}
|