mirror of
https://github.com/google/blockly.git
synced 2026-01-09 18:10:08 +01:00
Fix Blockly.utils.global when wrapped in a module. (#3035)
* Fix Blockly.utils.global when wrapped in a module.
This commit is contained in:
@@ -4,6 +4,7 @@ blockly_node_javascript_en.js
|
||||
gulpfile.js
|
||||
/msg/*
|
||||
/core/css.js
|
||||
/core/utils/global.js
|
||||
/tests/blocks/*
|
||||
/tests/compile/*
|
||||
/tests/jsunit/*
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* @fileoverview Core utility methods for Blockly
|
||||
* @fileoverview Provides a reference to the global object.
|
||||
* @author samelh@google.com (Sam El-Husseini)
|
||||
*/
|
||||
'use strict';
|
||||
@@ -33,6 +33,19 @@ goog.provide('Blockly.utils.global');
|
||||
|
||||
/**
|
||||
* Reference to the global object.
|
||||
*
|
||||
* More info on this implementation here:
|
||||
* https://docs.google.com/document/d/1NAeW4Wk7I7FV0Y2tcUFvQdGMc89k2vdgSXInw8_nvCI/edit
|
||||
*/
|
||||
Blockly.utils.global = this || self;
|
||||
|
||||
Blockly.utils.global = function() {
|
||||
if (typeof self === 'object') {
|
||||
return self;
|
||||
}
|
||||
if (typeof window === 'object') {
|
||||
return window;
|
||||
}
|
||||
if (typeof global === 'object') {
|
||||
return global;
|
||||
}
|
||||
return this;
|
||||
}();
|
||||
|
||||
@@ -509,8 +509,6 @@ function packageCommonJS(namespace, dependencies) {
|
||||
*/
|
||||
gulp.task('package-blockly', function() {
|
||||
return gulp.src('blockly_compressed.js')
|
||||
.pipe(gulp.insert.prepend(`
|
||||
var self = this;`))
|
||||
.pipe(packageUMD('Blockly', []))
|
||||
.pipe(gulp.rename('blockly.js'))
|
||||
.pipe(gulp.dest(packageDistribution));
|
||||
@@ -524,9 +522,8 @@ gulp.task('package-blockly', function() {
|
||||
gulp.task('package-blockly-node', function() {
|
||||
// Override textToDomDocument, providing a Node.js alternative to DOMParser.
|
||||
return gulp.src('blockly_compressed.js')
|
||||
.pipe(gulp.insert.wrap(`
|
||||
var self = global;`,
|
||||
`if (typeof DOMParser !== 'function') {
|
||||
.pipe(gulp.insert.append(`
|
||||
if (typeof DOMParser !== 'function') {
|
||||
var JSDOM = require('jsdom').JSDOM;
|
||||
var window = (new JSDOM()).window;
|
||||
var document = window.document;
|
||||
|
||||
Reference in New Issue
Block a user