Skip to content

Do not use arguments object#3102

Merged
JLHwung merged 6 commits intohexojs:masterfrom
segayuu:no-use-arguments
Apr 10, 2018
Merged

Do not use arguments object#3102
JLHwung merged 6 commits intohexojs:masterfrom
segayuu:no-use-arguments

Conversation

@segayuu
Copy link
Copy Markdown
Contributor

@segayuu segayuu commented Mar 30, 2018

Thank you for creating a pull request to contribute to Hexo code! Before you open the request please review the following guidelines and tips to help it be more easily integrated:

  • Add test cases for the changes.
  • Passed the CI test.

@segayuu segayuu requested a review from tommy351 March 30, 2018 04:30
@coveralls
Copy link
Copy Markdown

Coverage Status

Coverage decreased (-0.05%) to 97.213% when pulling 9f51f9d on segayuu:no-use-arguments into a846bbd on hexojs:master.

1 similar comment
@coveralls
Copy link
Copy Markdown

Coverage Status

Coverage decreased (-0.05%) to 97.213% when pulling 9f51f9d on segayuu:no-use-arguments into a846bbd on hexojs:master.

@coveralls
Copy link
Copy Markdown

coveralls commented Mar 30, 2018

Coverage Status

Coverage decreased (-0.05%) to 97.213% when pulling 488395b on segayuu:no-use-arguments into a846bbd on hexojs:master.

@segayuu segayuu changed the title No use arguments Do not use arguments object Apr 2, 2018
@segayuu segayuu requested review from a team and removed request for tommy351 April 6, 2018 04:05
Copy link
Copy Markdown

@demurgos demurgos left a comment

Choose a reason for hiding this comment

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

Rest parameters are available by default in Node 6 and above so there should be no issue with the versions supported by Hexo.
I added some other comments but overall it's a good change. Thanks.

I'd still would prefer others to check this PR.

const end = arguments[5];
const args = arguments[3].split('=').shift();
let content = arguments[4];
data.content = data.content.replace(rBacktick, ($0, start, $2, _args, content, end) => {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

It would be better to use non-capturing groups (?: ) in the regular expressions to avoid unused arguments.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

\2 is used in the RegExp literal and can not be deleted with node v6.
const rBacktick = /(\s*)(`{3,}|~{3,}) *(.*) *\n([\s\S]+?)\s*\2(\n+|$)/g;

swig.setTag('for', forTag.parse, function(compiler, args, content, parents, options, blockName) {
const compile = forTag.compile.apply(this, arguments).split('\n');
swig.setTag('for', forTag.parse, function(...args) {
const compile = forTag.compile.apply(this, args).split('\n');
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Is the thisArg used in forTag.compile? If no, it could be simplified to forTag.compile(...args).split('\n')

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I do not know if the value of this in the callback of swig.setTag() and the value of this in forTag.compile() do not know whether it works correctly or not.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@demurgos
Copy link
Copy Markdown

demurgos commented Apr 6, 2018

So, I tracked the relevant Node versions and I confirm it's fine. Rest parameters are supported since Node 6.

@segayuu segayuu requested a review from a team April 9, 2018 01:08
@JLHwung JLHwung merged commit 106980e into hexojs:master Apr 10, 2018
@segayuu segayuu deleted the no-use-arguments branch April 10, 2018 06:17
thom4parisot pushed a commit to thom4parisot/hexo that referenced this pull request Jan 17, 2020
* refactor: split function

* lodash.toArray to rest param

* remove arguments

* no use arguments

* fix param

* forTag.compile() does not use thisArg.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants