Skip to content

Commit 146f690

Browse files
committed
fix: apply changes from code review
1 parent 6e448e6 commit 146f690

10 files changed

Lines changed: 128 additions & 40 deletions

File tree

lib/node_modules/@stdlib/object/assign/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ var y = {
5454

5555
var z = assign( x, y );
5656

57+
var v = z.b;
58+
// returns 'boop'
59+
5760
var bool = ( z === x );
5861
// returns true
5962
```

lib/node_modules/@stdlib/object/assign/docs/repl.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222

2323
Examples
2424
--------
25-
> var obj1 = { 'name': 'John', 'age': 30 }
26-
> var obj2 = { 'country': 'US', 'city': 'San Francisco' }
25+
> var obj1 = { 'name': 'John', 'age': 30 };
26+
> var obj2 = { 'country': 'US', 'city': 'San Francisco' };
2727
> var result = {{alias}}( obj1, obj2 )
2828
{ 'name': 'John', 'age': 30, 'country': 'US', 'city': 'San Francisco' }
2929

lib/node_modules/@stdlib/object/assign/docs/types/index.d.ts

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,65 @@
1818

1919
// TypeScript Version: 4.1
2020

21+
/**
22+
* Copies own enumerable properties from one or more source objects to a target object.
23+
*
24+
* ## Notes
25+
*
26+
* - If a property key is present in multiple sources, the property from the last source that defines the key prevails.
27+
* - The target object is mutated.
28+
*
29+
* @param target - target object
30+
* @param source - source object
31+
* @throws first argument must not be null or undefined
32+
* @returns target object
33+
*
34+
* @example
35+
* var obj1 = {
36+
* 'a': 'beep'
37+
* };
38+
* var obj2 = {
39+
* 'b': 'boop'
40+
* };
41+
*
42+
* var out = assign( obj1, obj2 );
43+
* // returns { 'a': 'beep', 'b': 'boop' }
44+
*/
45+
declare function assign<T extends object, U>( target: T, source: U ): T & U;
46+
47+
/**
48+
* Copies own enumerable properties from one or more source objects to a target object.
49+
*
50+
* ## Notes
51+
*
52+
* - If a property key is present in multiple sources, the property from the last source that defines the key prevails.
53+
* - The target object is mutated.
54+
*
55+
* @param target - target object
56+
* @param source1 - first source object
57+
* @param source2 - second source object
58+
* @throws first argument must not be null or undefined
59+
* @returns target object
60+
*/
61+
declare function assign<T extends object, U, V>( target: T, source1: U, source2: V ): T & U & V; // tslint-disable-line max-line-length
62+
63+
/**
64+
* Copies own enumerable properties from one or more source objects to a target object.
65+
*
66+
* ## Notes
67+
*
68+
* - If a property key is present in multiple sources, the property from the last source that defines the key prevails.
69+
* - The target object is mutated.
70+
*
71+
* @param target - target object
72+
* @param source1 - first source object
73+
* @param source2 - second source object
74+
* @param source3 - third source object
75+
* @throws first argument must not be null or undefined
76+
* @returns target object
77+
*/
78+
declare function assign<T extends object, U, V, W>( target: T, source1: U, source2: V, source3: W ): T & U & V & W; // tslint-disable-line max-line-length
79+
2180
/**
2281
* Copies own enumerable properties from one or more source objects to a target object.
2382
*
@@ -42,7 +101,7 @@
42101
* var out = assign( obj1, obj2 );
43102
* // returns { 'a': 'beep', 'b': 'boop' }
44103
*/
45-
declare function assign( target: object, ...source: Array<object> ): object;
104+
declare function assign( target: object, ...source: Array<any> ): object;
46105

47106

48107
// EXPORTS //

lib/node_modules/@stdlib/object/assign/docs/types/test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import assign = require( './index' );
3030
{
3131
const obj1 = { 'name': 'John' };
3232
const obj2 = { 'country': 'US' };
33-
assign( obj1, obj2 ); // $ExpectType object
33+
assign( obj1, obj2 ); // $ExpectType { name: string; } & { country: string; }
3434
}
3535

3636
// The compiler throws an error if the function is provided a first argument which is not an object...

lib/node_modules/@stdlib/object/assign/lib/main.js renamed to lib/node_modules/@stdlib/object/assign/lib/builtin.js

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,34 @@
1818

1919
'use strict';
2020

21-
// VARIABLES //
21+
// MAIN //
2222

23+
/**
24+
* Copies own enumerable properties from source objects to a target object.
25+
*
26+
* ## Notes
27+
*
28+
* - If a property key is present in multiple sources, the property from the last source that defines the key prevails.
29+
* - The target object is mutated.
30+
*
31+
* @name assign
32+
* @type {Function}
33+
* @param {Object} target - target object
34+
* @param {...Object} source - source object(s)
35+
* @throws {TypeError} first argument must not be null or undefined
36+
* @returns {Object} target object
37+
*
38+
* @example
39+
* var obj1 = {
40+
* 'a': 'beep'
41+
* };
42+
* var obj2 = {
43+
* 'b': 'boop'
44+
* };
45+
*
46+
* var out = assign( obj1, obj2 );
47+
* // returns { 'a': 'beep', 'b': 'boop' }
48+
*/
2349
var assign = Object.assign; // eslint-disable-line node/no-unsupported-features/es-builtins
2450

2551

lib/node_modules/@stdlib/object/assign/lib/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
// MODULES //
3434

3535
var hasObjectAssign = require( './has_object_assign.js' );
36-
var main = require( './main.js' );
36+
var main = require( './builtin.js' );
3737
var polyfill = require( './polyfill.js' );
3838

3939

lib/node_modules/@stdlib/object/assign/lib/polyfill.js

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,15 @@
2020

2121
// MODULES //
2222

23+
var enumerableProperties = require( '@stdlib/utils/enumerable-properties' );
2324
var Object = require( '@stdlib/object/ctor' );
24-
var objectKeys = require( '@stdlib/utils/keys' );
25-
26-
27-
// VARIABLES //
28-
29-
var getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
25+
var format = require( '@stdlib/string/format' );
3026

3127

3228
// MAIN //
3329

3430
/**
35-
* Copies own and inherited enumerable properties from source objects to a target object.
31+
* Copies own enumerable properties from source objects to a target object.
3632
*
3733
* ## Notes
3834
*
@@ -57,15 +53,14 @@ var getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
5753
*/
5854
function assign( target ) {
5955
var source;
60-
var desc;
6156
var keys;
6257
var key;
6358
var len;
6459
var to;
6560
var i;
6661
var j;
6762
if ( target === void 0 || target === null ) {
68-
throw new TypeError( 'Cannot convert undefined or null to object' );
63+
throw new TypeError( format( 'invalid argument. First argument must be a non-null object. Value: %s' ) );
6964
}
7065
to = Object( target );
7166
for ( i = 1; i < arguments.length; i++ ) {
@@ -74,14 +69,11 @@ function assign( target ) {
7469
continue;
7570
}
7671

77-
keys = objectKeys( Object( source ) );
72+
keys = enumerableProperties( Object( source ) );
7873
len = keys.length;
7974
for ( j = 0; j < len; j++ ) {
8075
key = keys[ j ];
81-
desc = getOwnPropertyDescriptor( source, key );
82-
if ( desc !== void 0 && desc.enumerable ) {
83-
to[ key ] = source[ key ];
84-
}
76+
to[ key ] = source[ key ];
8577
}
8678
}
8779
return to;

lib/node_modules/@stdlib/object/assign/test/test.main.js renamed to lib/node_modules/@stdlib/object/assign/test/test.builtin.js

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,28 @@
2323
var tape = require( 'tape' );
2424
var hasSymbolSupport = require( '@stdlib/assert/has-symbol-support' );
2525
var Symbol = require( '@stdlib/symbol/ctor' );
26-
var assign = require( './../lib' );
26+
var assign = require( './../lib/builtin.js' );
2727

2828

2929
// VARIABLES //
3030

3131
var opts = {
32-
'skip': !hasSymbolSupport()
32+
'skip': ( typeof Object.assign === 'undefined' ) // eslint-disable-line node/no-unsupported-features/es-builtins
33+
};
34+
var optsSymbool = {
35+
'skip': opts.skip || !hasSymbolSupport()
3336
};
3437

3538

3639
// TESTS //
3740

38-
tape( 'main export is a function', function test( t ) {
39-
t.ok( typeof assign === 'function', 'main export is a function' );
41+
tape( 'main export is a function', opts, function test( t ) {
42+
t.ok( true, __filename );
43+
t.strictEqual( typeof assign, 'function', 'main export is a function' );
4044
t.end();
4145
});
4246

43-
tape( 'the function throws an error if provided `undefined` or `null` as a target object', function test( t ) {
47+
tape( 'the function throws an error if provided `undefined` or `null` as a target object', opts, function test( t ) {
4448
var values;
4549
var i;
4650

@@ -61,7 +65,7 @@ tape( 'the function throws an error if provided `undefined` or `null` as a targe
6165
}
6266
});
6367

64-
tape( 'the function returns the target object', function test( t ) {
68+
tape( 'the function returns the target object', opts, function test( t ) {
6569
var out;
6670
var obj;
6771

@@ -74,7 +78,7 @@ tape( 'the function returns the target object', function test( t ) {
7478
t.end();
7579
});
7680

77-
tape( 'the function assigns enumerable own properties of one or more source objects to a target object', function test( t ) {
81+
tape( 'the function assigns enumerable own properties of one or more source objects to a target object', opts, function test( t ) {
7882
var expected;
7983
var obj1;
8084
var obj2;
@@ -103,7 +107,7 @@ tape( 'the function assigns enumerable own properties of one or more source obje
103107
t.end();
104108
});
105109

106-
tape( 'the function copies symbol-typed properties', opts, function test( t ) {
110+
tape( 'the function copies symbol-typed properties', optsSymbool, function test( t ) {
107111
var expected;
108112
var obj1;
109113
var obj2;
@@ -125,11 +129,12 @@ tape( 'the function copies symbol-typed properties', opts, function test( t ) {
125129
};
126130
expected[ sym ] = 'boop';
127131

128-
t.deepEqual( out, expected, 'returns expected object' );
132+
t.strictEqual( out[ sym ], expected[ sym ], 'returns expected object' );
133+
t.strictEqual( out.a, expected.a, 'returns expected object' );
129134
t.end();
130135
});
131136

132-
tape( 'the function wraps primitives to objects', function test( t ) {
137+
tape( 'the function wraps source primitives as objects before assignment', opts, function test( t ) {
133138
var expected;
134139
var obj1;
135140
var obj2;

lib/node_modules/@stdlib/object/assign/test/test.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,31 +23,32 @@
2323
var tape = require( 'tape' );
2424
var proxyquire = require( 'proxyquire' );
2525
var assign = require( './../lib' );
26-
var native = require( './../lib/main.js' );
26+
var native = require( './../lib/builtin.js' );
2727
var polyfill = require( './../lib/polyfill.js' );
2828

2929

3030
// TESTS //
3131

32-
tape( 'module exports a function ', function test( t ) {
33-
t.equal( typeof assign, 'function', 'main export is a function' );
32+
tape( 'main export is a function', function test( t ) {
33+
t.ok( true, __filename );
34+
t.strictEqual( typeof assign, 'function', 'main export is a function' );
3435
t.end();
3536
});
3637

37-
tape( 'module exports the native function in environments with `Object.assign` support', function test( t ) {
38+
tape( 'if an environment has a built-in implementation, the export is the built-in implementation', function test( t ) {
3839
var assign = proxyquire( './../lib', {
3940
'./has_object_assign.js': true
4041
});
4142

42-
t.equal(assign, native, 'exports native function'); //
43+
t.equal( assign, native, 'exports native function' );
4344
t.end();
4445
});
4546

46-
tape( 'module exports a polyfill function in environments without `Object.assign` support', function test( t ) {
47+
tape( 'if an environment does not have a built-in implementation, the export is a polyfill', function test( t ) {
4748
var assign = proxyquire( './../lib', {
4849
'./has_object_assign.js': false
4950
});
5051

51-
t.equal(assign, polyfill, 'exports polyfill function');
52+
t.equal( assign, polyfill, 'exports polyfill function' );
5253
t.end();
5354
});

lib/node_modules/@stdlib/object/assign/test/test.polyfill.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ var opts = {
3636
// TESTS //
3737

3838
tape( 'main export is a function', function test( t ) {
39-
t.ok( typeof assign === 'function', 'main export is a function' );
39+
t.ok( true, __filename );
40+
t.strictEqual( typeof assign, 'function', 'main export is a function' );
4041
t.end();
4142
});
4243

@@ -125,11 +126,12 @@ tape( 'the function copies symbol-typed properties', opts, function test( t ) {
125126
};
126127
expected[ sym ] = 'boop';
127128

128-
t.deepEqual( out, expected, 'returns expected object' );
129+
t.strictEqual( out[ sym ], expected[ sym ], 'returns expected object' );
130+
t.strictEqual( out.a, expected.a, 'returns expected object' );
129131
t.end();
130132
});
131133

132-
tape( 'the function wraps primitives to objects', function test( t ) {
134+
tape( 'the function wraps source primitives as objects before assignment', function test( t ) {
133135
var expected;
134136
var obj1;
135137
var obj2;

0 commit comments

Comments
 (0)