Giter Site home page Giter Site logo

Comments (2)

mlegenhausen avatar mlegenhausen commented on July 21, 2024 2

Never mind. The problem was not in this babel plugin, simply had some wired behaviour in getting this stuff working with webpack, typescript and awesome-typescript-loader. For everyone looking around for a configuration here is mine:

// tsconfig.js
{
  ...
  "awesomeTypescriptLoaderOptions": {
    "useBabel": true,
    "babelOptions": {
      "plugins": ["angularjs-annotate"],
      "presets": ["es2015"]
    }
  }
}

Don't try to chain awesome-typescript-loader with babel-loader this will create the above described error.

from babel-plugin-angularjs-annotate.

schmod avatar schmod commented on July 21, 2024

Extended ES6 classes seem to work fine.

class foo extends bar {
  constructor($scope){
    "ngInject";
    super();
  }
}

new foo();

Yields

"use strict";

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }

var foo = function (_bar) {
  foo.$inject = ["$scope"];

  _inherits(foo, _bar);

  function foo($scope) {
    "ngInject";

    _classCallCheck(this, foo);

    return _possibleConstructorReturn(this, Object.getPrototypeOf(foo).call(this));
  }

  return foo;
}(bar);

new foo();

In this example, $inject is defined before _inherits(foo,_bar) is called.

I don't quite understand why this isn't happening with awesome-typescript-loader, but there may be nothing that we can do about it (particularly if the TS loader is invoked after Babel).

If you don't have any objections, I'm going to close this, as I'm not sure there's anything else to do at this point.

from babel-plugin-angularjs-annotate.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.