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

Update is-shallow-equal to use ES5 code as before #8132

Merged
merged 2 commits into from
Jul 23, 2018
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
5 changes: 5 additions & 0 deletions packages/is-shallow-equal/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note for future reference in extracting rules: We should consider having separate rulesets for ES5 vs. ES2015+ .

Looks like this is already built-in to eslint-plugin-wordpress:

https://github.com/WordPress-Coding-Standards/eslint-plugin-wordpress#available-rulesets

(Confused why there's both a config and a plugin which includes rulesets)

Copy link
Member Author

@gziolo gziolo Jul 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, it would be much easier to put the following:

{
    "root": true,
    "extends": "something"
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"rules": {
"no-var": 0
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

/**
* Returns true if the two arrays are shallow equal, or false otherwise.
*
Expand All @@ -7,6 +9,8 @@
* @return {boolean} Whether the two arrays are shallow equal.
*/
function isShallowEqualArrays( a, b ) {
var i;

if ( a === b ) {
return true;
}
Expand All @@ -15,7 +19,7 @@ function isShallowEqualArrays( a, b ) {
return false;
}

for ( let i = 0; i < a.length; i++ ) {
for ( i = 0; i < a.length; i++ ) {
if ( a[ i ] !== b[ i ] ) {
return false;
}
Expand All @@ -24,4 +28,4 @@ function isShallowEqualArrays( a, b ) {
return true;
}

export default isShallowEqualArrays;
module.exports = isShallowEqualArrays;
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
/**
* Internal dependencies
*/
import isShallowEqualObjects from './objects';
import isShallowEqualArrays from './arrays';
'use strict';

/**
* Local variables
* Internal dependencies;
*/
const { isArray } = Array;
var isShallowEqualObjects = require( './objects' );
var isShallowEqualArrays = require( './arrays' );

var isArray = Array.isArray;

/**
* Returns true if the two arrays or objects are shallow equal, or false
Expand All @@ -30,4 +29,4 @@ function isShallowEqual( a, b ) {
return a === b;
}

export default isShallowEqual;
module.exports = isShallowEqual;
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/**
* Local variables
*/
const { keys } = Object;
'use strict';

var keys = Object.keys;

/**
* Returns true if the two objects are shallow equal, or false otherwise.
Expand All @@ -12,21 +11,23 @@ const { keys } = Object;
* @return {boolean} Whether the two objects are shallow equal.
*/
function isShallowEqualObjects( a, b ) {
var aKeys, bKeys, i, key;

if ( a === b ) {
return true;
}

const aKeys = keys( a );
const bKeys = keys( b );
aKeys = keys( a );
bKeys = keys( b );

if ( aKeys.length !== bKeys.length ) {
return false;
}

let i = 0;
i = 0;

while ( i < aKeys.length ) {
const key = aKeys[ i ];
key = aKeys[ i ];
if ( a[ key ] !== b[ key ] ) {
return false;
}
Expand All @@ -37,4 +38,4 @@ function isShallowEqualObjects( a, b ) {
return true;
}

export default isShallowEqualObjects;
module.exports = isShallowEqualObjects;
7 changes: 5 additions & 2 deletions packages/is-shallow-equal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@
"bugs": {
"url": "https://github.com/WordPress/gutenberg/issues"
},
"main": "build/index.js",
"module": "build-module/index.js",
"files": [
"arrays.js",
"objects.js"
],
"main": "index.js",
"dependencies": {
"@babel/runtime": "^7.0.0-beta.52"
},
Expand Down
2 changes: 1 addition & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ const config = {
test: /\.js$/,
exclude: [
/block-serialization-spec-parser/,
/is-shallow-equal/,
/node_modules/,
],
use: 'babel-loader',
Expand Down Expand Up @@ -233,7 +234,6 @@ const config = {
'api-fetch',
'deprecated',
'dom-ready',
'is-shallow-equal',
].map( camelCaseDash ) ),
],
stats: {
Expand Down