ts-optchain icon indicating copy to clipboard operation
ts-optchain copied to clipboard

TypeScript Custom Code Transformer does not work

Open unlight opened this issue 6 years ago • 2 comments
trafficstars

Install instruction to setup TypeScript Custom Code Transformer https://github.com/rimeto/ts-optchain#typescript-custom-code-transformer

  1. Using TTypescript Bundle contains
/***/ "./node_modules/ts-optchain/dist/proxy/index.js":
/*!******************************************************!*\
  !*** ./node_modules/ts-optchain/dist/proxy/index.js ***!
  \******************************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {

"use strict";

/**
 * Copyright (C) 2019-present, Rimeto, LLC.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */
Object.defineProperty(exports, "__esModule", { value: true });
/**
 * Proxy based implementation of optional chaining w/ default values.
 */
function oc(data) {
    return new Proxy((function (defaultValue) { return (data == null ? defaultValue : data); }), {
        get: function (target, key) {
            var obj = target();
            return oc(typeof obj === 'object' ? obj[key] : undefined);
        },
    });
}
exports.oc = oc;

I do not see transformed result, e.g.

  const value =
    (obj != null && obj.propA != null && obj.propA.propB != null && obj.propA.propB.propC != null)
      ? obj.propA.propB.propC
      : defaultValue;
  1. Same result when using getCustomTransformers of ts-loader Part of webpack.config
                            getCustomTransformers: program => ({
                                before: [
                                    require('ts-optchain/transform').default(program),
                                ]
                            }),

Environment

node 12.6
+-- [email protected]
+-- [email protected]
+-- [email protected]
`-- [email protected]

unlight avatar Jul 12 '19 19:07 unlight

Same problem!

Anyone managed to solve this?

mmontes11 avatar Apr 21 '20 16:04 mmontes11

This is not an issue for me, since typescript 3.7 with optional chaining feature.

unlight avatar Apr 21 '20 16:04 unlight