* @param array $localFileRefs List of files
*/
protected function saveFileDependencies( ResourceLoaderContext $context, $localFileRefs ) {
-
try {
// Related bugs and performance considerations:
// 1. Don't needlessly change the database value with the same list in a
$scripts = $this->getScriptURLsForDebug( $context );
} else {
$scripts = $this->getScript( $context );
- // rtrim() because there are usually a few line breaks
- // after the last ';'. A new line at EOF, a new line
- // added by ResourceLoaderFileModule::readScriptFiles, etc.
+ // Make the script safe to concatenate by making sure there is at least one
+ // trailing new line at the end of the content. Previously, this looked for
+ // a semi-colon instead, but that breaks concatenation if the semicolon
+ // is inside a comment like "// foo();". Instead, simply use a
+ // line break as separator which matches JavaScript native logic for implicitly
+ // ending statements even if a semi-colon is missing.
+ // Bugs: T29054, T162719.
if ( is_string( $scripts )
&& strlen( $scripts )
- && substr( rtrim( $scripts ), -1 ) !== ';'
+ && substr( $scripts, -1 ) !== "\n"
) {
- // Append semicolon to prevent weird bugs caused by files not
- // terminating their statements right (T29054)
- $scripts .= ";\n";
+ $scripts .= "\n";
}
}
$content['scripts'] = $scripts;
// (e.g. startup module) iterate more than once over all modules to get versions.
$contextHash = $context->getHash();
if ( !array_key_exists( $contextHash, $this->versionHash ) ) {
-
if ( $this->enableModuleContentVersion() ) {
// Detect changes directly
$str = json_encode( $this->getModuleContent( $context ) );
return false;
}
+ /**
+ * Check whether this module should be embeded rather than linked
+ *
+ * Modules returning true here will be embedded rather than loaded by
+ * ResourceLoaderClientHtml.
+ *
+ * @since 1.30
+ * @param ResourceLoaderContext $context
+ * @return bool
+ */
+ public function shouldEmbedModule( ResourceLoaderContext $context ) {
+ return $this->getGroup() === 'private';
+ }
+
/** @var JSParser Lazy-initialized; use self::javaScriptParser() */
private static $jsParser;
private static $parseCacheVersion = 1;