From e006e65d198edb7fc2ac35f988f313882f34202b Mon Sep 17 00:00:00 2001 From: Johannes Rieken Date: Thu, 25 Aug 2016 12:04:25 +0200 Subject: [PATCH] nicer WorkspaceConfiguration creation, #1396 --- .../api/node/extHostConfiguration.ts | 32 +++++++++---------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/src/vs/workbench/api/node/extHostConfiguration.ts b/src/vs/workbench/api/node/extHostConfiguration.ts index 1a91cf5ecf5..f2def6b8dd2 100644 --- a/src/vs/workbench/api/node/extHostConfiguration.ts +++ b/src/vs/workbench/api/node/extHostConfiguration.ts @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------------*/ 'use strict'; -import {clone} from 'vs/base/common/objects'; +import {mixin} from 'vs/base/common/objects'; import {illegalState} from 'vs/base/common/errors'; import Event, {Emitter} from 'vs/base/common/event'; import {WorkspaceConfiguration} from 'vscode'; @@ -43,25 +43,23 @@ export class ExtHostConfiguration extends ExtHostConfigurationShape { ? ExtHostConfiguration._lookUp(section, this._config) : this._config; - let result: any; - if (typeof config !== 'object') { - // this catches missing config and accessing values - result = {}; - } else { - result = clone(config); - } - - result.has = function(key: string): boolean { - return typeof ExtHostConfiguration._lookUp(key, config) !== 'undefined'; - }; - result.get = function (key: string, defaultValue?: T): T { - let result = ExtHostConfiguration._lookUp(key, config); - if (typeof result === 'undefined') { - result = defaultValue; + const result: WorkspaceConfiguration = { + has(key: string): boolean { + return typeof ExtHostConfiguration._lookUp(key, config) !== 'undefined'; + }, + get(key: string, defaultValue?: T): T { + let result = ExtHostConfiguration._lookUp(key, config); + if (typeof result === 'undefined') { + result = defaultValue; + } + return result; } - return result; }; + if (typeof config === 'object') { + mixin(result, config, false); + } + return Object.freeze(result); }