Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

When a snippet's prefix equal 'hasOwnProperty', the Atom will throw an error #209

Closed
gxvv opened this issue Jul 20, 2016 · 1 comment
Closed

Comments

@gxvv
Copy link

gxvv commented Jul 20, 2016

My snippet:

'.source.js':
    '{}.hasOwnProperty':
        'prefix': 'hasOwnProperty'
        'body': '${1:obj}.hasOwnProperty(${2:prop})$0'

Developer Tools throw error

C:\Users\gaox\AppData\Local\atom\app-1.8.0\resources\app.asar\node_modules\scoped-property-store\lib\helpers.js :line34

deepDefaults = function(target, defaults) {
    var key, _i, _len, _ref;
    if (isPlainObject(target) && isPlainObject(defaults)) {
      _ref = Object.keys(defaults);
      for (_i = 0, _len = _ref.length; _i < _len; _i++) {
        key = _ref[_i];
        if (target.hasOwnProperty(key)) {                  <------line:34----
          deepDefaults(target[key], defaults[key]);
        } else {
          target[key] = defaults[key];
        }
      }
    }
  };

I think the reason is that the prefix's value replaced the original property of the Object.
I have an idea to resolve it.

({}).hasOwnProperty.call(target, key);
// Is this a good idea ?

Atom throw error

[Enter steps to reproduce below:]

  1. ...
  2. ...

Atom Version: 1.8.0
System: Unknown Windows Version
Thrown From: snippets package, v1.0.2

Stack Trace

Uncaught TypeError: target.hasOwnProperty is not a function

At C:\Users\gaox\AppData\Local\atom\app-1.8.0\resources\app.asar\node_modules\scoped-property-store\lib\helpers.js:34

TypeError: target.hasOwnProperty is not a function
    at deepDefaults (C:\Users\gaox\AppData\Local\atom\app-1.8.0\resources\app.asar\node_modules\scoped-property-store\lib\helpers.js:34:20)
    at C:\Users\gaox\AppData\Local\atom\app-1.8.0\resources\app.asar\node_modules\scoped-property-store\lib\scoped-property-store.js:71:21
    at ScopedPropertyStore.module.exports.ScopedPropertyStore.withCaching (C:\Users\gaox\AppData\Local\atom\app-1.8.0\resources\app.asar\node_modules\scoped-property-store\lib\scoped-property-store.js:220:39)
    at ScopedPropertyStore.module.exports.ScopedPropertyStore.getPropertyValue (C:\Users\gaox\AppData\Local\atom\app-1.8.0\resources\app.asar\node_modules\scoped-property-store\lib\scoped-property-store.js:51:19)
    at Object.module.exports.parsedSnippetsForScopes (C:\Users\gaox\AppData\Local\atom\app-1.8.0\resources\app.asar\node_modules\snippets\lib\snippets.js:355:59)
    at SnippetsProvider.module.exports.SnippetsProvider.getSuggestions (C:\Users\gaox\AppData\Local\atom\app-1.8.0\resources\app.asar\node_modules\autocomplete-snippets\lib\snippets-provider.js:38:43)
    at C:\Users\gaox\AppData\Local\atom\app-1.8.0\resources\app.asar\node_modules\autocomplete-plus\lib\autocomplete-manager.js:310:56
    at Array.forEach (native)
    at AutocompleteManager.module.exports.AutocompleteManager.getSuggestionsFromProviders (C:\Users\gaox\AppData\Local\atom\app-1.8.0\resources\app.asar\node_modules\autocomplete-plus\lib\autocomplete-manager.js:289:17)
    at AutocompleteManager.getSuggestionsFromProviders (C:\Users\gaox\AppData\Local\atom\app-1.8.0\resources\app.asar\node_modules\autocomplete-plus\lib\autocomplete-manager.js:3:61)
    at AutocompleteManager.module.exports.AutocompleteManager.findSuggestions (C:\Users\gaox\AppData\Local\atom\app-1.8.0\resources\app.asar\node_modules\autocomplete-plus\lib\autocomplete-manager.js:276:19)
    at C:\Users\gaox\AppData\Local\atom\app-1.8.0\resources\app.asar\node_modules\autocomplete-plus\lib\autocomplete-manager.js:3:61

Commands

     -0:11.1.0 grammar-selector:show (atom-text-editor.editor.is-focused)
     -0:09.6.0 core:confirm (atom-text-editor.editor.mini.is-focused)

Config

{
  "core": {
    "autoHideMenuBar": true,
    "disabledPackages": [
      "activate-power-mode",
      "javascript-snippets",
      "nodejs-snippets"
    ],
    "themes": [
      "atom-light-ui",
      "atom-light-syntax"
    ]
  }
}

Installed Packages

# User
atom-ternjs, v0.14.2
docblockr, v0.7.3
emmet, v2.4.3
jquery-snippets, v11.0.0
jshint, v1.8.5
linter, v1.11.14
linter-htmlhint, v1.2.1
linter-jshint, v2.1.0
minimap, v4.24.7
minimap-find-and-replace, v4.5.1

# Dev
No dev packages
@savetheclocktower
Copy link
Contributor

Duplicate of #247.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants