Last modified: 2014-07-21 10:30:32 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T70280, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 68280 - ResourceLoader: Skip files should be valid javascript files
ResourceLoader: Skip files should be valid javascript files
Status: RESOLVED WONTFIX
Product: MediaWiki
Classification: Unclassified
ResourceLoader (Other open bugs)
1.24rc
All All
: Lowest enhancement (vote)
: ---
Assigned To: Nobody - You can work on this!
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2014-07-19 20:11 UTC by Umherirrender
Modified: 2014-07-21 10:30 UTC (History)
5 users (show)

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments

Description Umherirrender 2014-07-19 20:11:06 UTC
For the three skip files my IDE gives "Cannot return from outside a function or method"

It is possible to make the skip files valid javascript files to avoid noise in my or any IDE or is something wrong with my IDE and the js validation (eclipse)?
Comment 1 Bartosz Dziewoński 2014-07-19 20:36:35 UTC
Krinkle has previously said that this is indeed valid (I never tried to find out, personally). See https://gerrit.wikimedia.org/r/#/c/139308/1//COMMIT_MSG and some other comments on that changeset.
Comment 2 Krinkle 2014-07-19 20:57:32 UTC
Also note that this is the result of various different attempts and compromises.

The dozens of other approaches all involved bloating the startup module output, repeating the same boilerplate in lots of files, or ending up with error pronse constructions, or files that aren't valid on their own.

These files are valid javascript code (as verified by jshint). Returning from outside a function is indeed a syntax error if it were executed like that, but it's executed as a function, not as a standalone program.

Some of the alternatives I considered:

--- func
function skip() {
  return true;
}

* Downside: Trips jshint's quality rule against having unused functions. We'd have to put /*jshint unused:false */ atop each file.

-- block
skip: {
  return true;
}

* This makes use of javascript supporting (goto/continue-like) label statements and unattached block statements to wrap code.
* If executed standalone would be an illegal return statement.

-- expression
true;

* This makes use of javascript supporting bare expression statements.
* Downside: Trips jshint's quality rule against having code that does not assign or invoke anything. We'd have to put /*jshint expr:true */ atop each file.

-- return
return true;

* If executed standalone would be an illegal return statement.


--
For 'func' and 'block':
* Extra boilerplate to repeat in each file.
* Either bloats the startup module and requires the client to perform extra actions to invoke it (due to name collision otherwise), or, it could be stripped by the server and reduced to 'return true;' but in that case it needs to be very exact. And anything outside of it would be ignored or result in an error. I think if all files contain the same character-by-character prefix/suffix only to be stripped, and result in exceptions when not exactly the same, might as well not have it.


The cleanest of these are 'block' and 'return'. They require no jshint overrides, is valid javascript passing jshint. Of those 'return' seemed the best.
Comment 3 Umherirrender 2014-07-21 10:30:32 UTC
eclipse validates the .js files with a global context and than the return makes a problem.

I should try to install jshint as eclipse plug-in and disable the build-in javascript validation.

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links