SqrTT / prophet

Prophet Debugger (SFCC sandboxes via SDAPI 2.0) extension for VS Code
https://marketplace.visualstudio.com/items?itemName=SqrTT.prophet
Other
144 stars 59 forks source link

req snippet doesn't work for CacheMgr #347

Closed foegit closed 1 year ago

foegit commented 1 year ago

req snippet doesn't work for CacheMgr (https://documentation.b2c.commercecloud.salesforce.com/DOC2/topic/com.demandware.dochelp/DWAPI/scriptapi/html/api/class_dw_system_CacheMgr.html)

To Reproduce

  1. Open any BE script type reqCache

Expected behavior The extension suggests a snippet to be inserted var CacheMgr = require('dw/system/CacheMgr');

Screenshots image

Desktop (please complete the following information):

SqrTT commented 1 year ago

Hi @foegit Thanks for reporting

It will be fixed within in next release.

aduponchel commented 1 year ago

You can add the following snippet for Javascript files.

{
    "Require Class Cache": {
        "prefix": "reqCache",
        "body": [
            "const Cache = require('dw/system/Cache');"
        ],
        "description": "Require Class Cache"
    },
    "Require Class CacheMgr": {
        "prefix": "reqCacheMgr",
        "body": [
            "const CacheMgr = require('dw/system/CacheMgr');"
        ],
        "description": "Require Class CacheMgr"
    },
}

Please note I use const instead of var. I noticed before 2019 const was used instead of var. I don't know why but will appreciate to know :) I always use const except in ISML iscript due to hoisting.

Regards

SqrTT commented 1 year ago

Hi @aduponchel const in not recommend to use since it has non standard behavior in comparison to ES6. For instance it has lexical scope instead of block scope. Try to guess result value after next code:

var result = ''

if (true) {
    const test = 'second'
}
result = test

or this code also will work

var result = ''
const test
if (true) {
    test = 'second'
}
result = test

or this example:

const product = getProduct(/*...*/)

if (true) {
    // SFCC will throw error here while ES6 just create new block scoped variable
    const product = getProduct(/*...*/)
}

none of this error can be catched by IDE or eslint since tools counts on ES6 standart.

Please note: Salesforce avoid usage of const in SFRA (along with let and empty)

SqrTT commented 1 year ago

fixed in 1.4.34