From 68814040e3d7117518c2b9aefa8b4e1f99e3ee49 Mon Sep 17 00:00:00 2001 From: George Kalpakas Date: Mon, 4 Jun 2018 22:38:08 +0300 Subject: [PATCH] fix(language-service): do not overwrite native `Reflect` (#24299) Fixes #21420 PR Close #24299 --- .../language-service/bundles/banner.js.txt | 5 +++-- packages/language-service/rollup.config.js | 18 ++---------------- 2 files changed, 5 insertions(+), 18 deletions(-) diff --git a/packages/language-service/bundles/banner.js.txt b/packages/language-service/bundles/banner.js.txt index 06ae8052bc..82e0ee92b0 100644 --- a/packages/language-service/bundles/banner.js.txt +++ b/packages/language-service/bundles/banner.js.txt @@ -4,8 +4,9 @@ * License: MIT */ -var $reflect = {defineMetadata: function() {}, getOwnMetadata: function(){}}; -((typeof global !== 'undefined' && global)||{})['Reflect'] = $reflect; +var $reflect = {defineMetadata: function() {}, getOwnMetadata: function() {}}; +var Reflect = (typeof global !== 'undefined' ? global : {})['Reflect'] || {}; +Object.keys($reflect).forEach(function(key) { Reflect[key] = Reflect[key] || $reflect[key]; }); var $deferred, $resolved, $provided; function $getModule(name) { return $provided[name] || require(name); } function define(modules, cb) { $deferred = { modules: modules, cb: cb }; } diff --git a/packages/language-service/rollup.config.js b/packages/language-service/rollup.config.js index fcf413351b..7404f938e4 100644 --- a/packages/language-service/rollup.config.js +++ b/packages/language-service/rollup.config.js @@ -9,12 +9,12 @@ const commonjs = require('rollup-plugin-commonjs'); const sourcemaps = require('rollup-plugin-sourcemaps'); const path = require('path'); +const fs = require('fs'); var m = /^\@angular\/((\w|\-)+)(\/(\w|\d|\/|\-)+)?$/; var location = normalize('../../dist/packages-dist') + '/'; var rxjsLocation = normalize('../../node_modules/rxjs'); var tslibLocation = normalize('../../node_modules/tslib'); -var esm = 'esm/'; var locations = {'compiler-cli': normalize('../../dist/packages') + '/'}; @@ -43,21 +43,7 @@ function resolve(id, from) { } } -var banner = ` -var $reflect = {defineMetadata: function() {}, getOwnMetadata: function(){}}; -((typeof global !== 'undefined' && global)||{})['Reflect'] = $reflect; -var $deferred, $resolved, $provided; -function $getModule(name) { return $provided[name] || require(name); } -function define(modules, cb) { $deferred = { modules: modules, cb: cb }; } -module.exports = function(provided) { - if ($resolved) return $resolved; - var result = {}; - $provided = Object.assign({'reflect-metadata': $reflect}, provided || {}, { exports: result }); - $deferred.cb.apply(this, $deferred.modules.map($getModule)); - $resolved = result; - return result; -} -`; +var banner = fs.readFileSync('bundles/banner.js.txt', 'utf8'); module.exports = { entry: '../../dist/packages-dist/language-service/fesm5/language-service.js',