Issue with ng-annotate when using Babel and object destructuring

Encountering a peculiar issue while transpiling to ES6 using Babel, where ng-annotate seems to have an aversion to destructuring. I decided to test my code in the online Babel compiler and it worked without any errors. Interestingly, disabling ng-annotate in my gulp pipeline removed the error altogether. Even manually injecting annotations by removing /* @ngAnnotate */ from the file didn't have any effect.

Here is the relevant section from my Gulp tasks:

return gulp.src(config.scripts.app)
    .pipe(changed(config.dist + '/scripts'))
    .pipe(plumber())
    .pipe(annotate())

    // Filtering and transpiling only .es6.js files
    .pipe(es6)
    .pipe(babel({
        presets: ['es2015'],
        plugins: ['extensible-destructuring'],
        comments: false
    }))
    .pipe(es6.restore)

    .pipe(concat('scripts.js'))
    .pipe(gulp.dest(config.dist + '/scripts'))

Snippet of the source code causing the issue:

var [min, max] = values.map(val => +val);
// Whether using let or var doesn't seem to matter.

ngModelCtrl.$modelValue = [min, max];

The error stems from a dependency within ng-annotate:

Error: StringMap expected string key
    at stringmap.set (/Users/macbookair/Places/app/places/frontend/node_modules/gulp-ng-annotate/node_modules/ng-annotate/node_modules/stringmap/stringmap.js:101:19)
    at Scope.add (/Users/macbookair/Places/app/places/frontend/node_modules/gulp-ng-annotate/node_modules/ng-annotate/build/es5/scope.js:102:17)
    at /Users/macbookair/Places/app/places/frontend/node_modules/gulp-ng-annotate/node_modules/ng-annotate/build/es5/scopetools.js:38:25
    at Array.forEach (native)
    .... more

The problematic function in stringmap.js:

stringmap.prototype.set = function(key, value) {    
    if (typeof key !== "string") {
        throw new Error("StringMap expected string key");
    }
    if (key === "__proto__") {
        this.hasProto = true;
        this.proto = value;
    } else {
        this.obj[key] = value;
    }
};

Upon logging out key and value in the above function, this is returned:

undefined { 
    kind: 'var', 
    node: { 
        type: 'ArrayPattern',
        start: 1178,
        end: 1188,
        loc: { start: [Object], end: [Object] },
        range: [ 1178, 1188 ],
        elements: [ [Object], [Object] ] 
    },
    from: 1215 
}

It's evident that the key argument is undefined, but the underlying reason for its significance remains elusive.

Answer №1

I encountered a similar issue, but was able to resolve it by changing the order in my gulp pipe to: babel --> annotate. It appears that ng-annotate does not support newer JavaScript versions, as discussed here: github.com/olov/ng-annotate/issues/237

This solution was originally provided by @illagrenan in the comment section above

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Ways to protect my client's password in API response

I am relatively new to the world of JavaScript and MERN stack development. Currently, I am working on building a small-scale social media application. However, while coding the sign-up API, I encountered an issue where I could not properly segregate and hi ...

Easiest homemade variations and pairings

Imagine having a basic array like ["apple", "banana", "lemon", "mango"];. For example, if we were to find the straightforward hand-rolled combinations of this array, selecting 3 items, but allowing for repetition: let array = ["apple", "banana", "lemon", ...

Issue where the selected value from Semantic UI React dropdown fails to display after being chosen

I'm struggling to display the selected value from the dropdown inside the dropdown itself after it's been chosen. Even though the correct value is being set (verified through console logging), it doesn't show up in the actual dropdown. ...

Transfer the contents of a field in an Object Array to a new simple Array using PHP

My PHP Object Array has multiple fields that need to be extracted and stored in separate arrays in order to pass them to a bash script. Since bash is not object oriented, having individual arrays is preferred. This is what I am attempting to achieve: < ...

How can I ensure the carousel stays centered on a webpage even after resizing the browser window?

Currently in the process of developing a website, I have implemented a jquery-based carousel on the homepage sourced from here. However, substantial modifications were made to tailor its appearance specifically for the site. The issue at hand is that I hav ...

CSS changes triggered by JQuery are ineffective

Having trouble modifying the CSS of a class in my HTML file. I've been struggling with this for quite some time and can't figure out what I'm doing wrong. (I've already attempted multiple versions, but nothing seems to work) Here' ...

`Can you teach me how to dynamically load HTML elements using input JSON data?`

What is the best way to iterate through an input array of objects? I currently have data for only 2 people included. However, there are more than 50 people's information in the input and I need to loop through all of them. Here is a sample code snip ...

To successfully process this file type in JavaScript, you might require a suitable loader

Currently, I am facing an issue with my MVC application while trying to integrate Bootstrap 5 using Webpack. Despite attempting various workarounds with stage-0, stage-2, and stage-3, none have proven successful for me. I suspect that the problem lies wit ...

Popup appears on incorrect page

As part of my app development project, I implemented a popover feature that opens when clicking on a label. Initially, this functioned smoothly within a tab navigation setup. However, after transitioning from tab modules to the app-routing module to displa ...

Using Webpack to directly embed image paths in your code

I am working on a project that uses webpack and vue.js. I encountered an issue when trying to add an image to the vue template using src '/images/imageName.png', which resulted in a 404 error. How can I adjust the configuration to recognize absol ...

How can you use Jquery's .data() method to find elements with specific values?

I have a button that generates a new drop pin. The pin is contained within a div, and a hidden form input is also created to store the position of the pin when it's dragged. In my jQuery code for creating these elements, I assign a data attribute call ...

Exploring the concept of making nested API requests within a route using Node.js and

Being a newbie in the world of coding, I'm excited to make my first post here. My current learning project involves developing a website that utilizes an external CRM for storing client data received from web forms. The storage functionality is up an ...

Vue issue causing problems with Rangy library: "..." throwing a function error specifically within hooks

Utilizing the Rangy library in a Vue component enables me to highlight individual words within text. Everything functions smoothly when Rangy is invoked from any method within the methods object: let applier = rangy.createClassApplier('some-class&apo ...

Utilizing Multer for temporarily storing a file in memory before parsing and transferring it to the database

As a newcomer to programming, I am attempting to describe my issue concisely. I am utilizing multer to upload an XML file in conjunction with a Node Express server and React with .jsx. My intention is to parse the uploaded file data and post it to a Postgr ...

Filtering data from Arduino using web serial communication

My setup consists of an Arduino kit connected to a webserial API that sends data to an HTML div identified by the id 'target'. Currently, all the data is being logged into one stream despite having multiple dials and switches on the Arduino. Th ...

What could be the reason behind my data validations not functioning as expected?

I have been working on a project using Angular 2 to create an application with a form that users can fill out. However, I am facing an issue where the validation messages do not disappear after the required fields are populated. Specifically, the message " ...

Ways to activate touch events in pjax library?

As I work on developing a website, I am utilizing the Pjax library, which is a port of jquery pjax. However, I have encountered an issue where touch events are not being processed. My implementation of Pjax looks like this: var pjax = new Pjax({ selectors ...

Displaying characteristics depending on chosen checkboxes

In the CodeSandBox comments, I have outlined the issues. To elaborate, I have an array named field.names that is used to render checkboxes. The goal is for users to be able to enter individual values for lengthType and size when selecting a checkbox. Howev ...

When using Stripe checkout, the database IDs are altered, causing issues when trying to delete or update stock in the database using a webhook

I have been working on developing an ecommerce platform using NextJs, Sanity as the CMS, and Stripe as the payment gateway. However, I have encountered an issue during the checkout process. When creating the checkout session, Stripe seems to alter the prod ...

The 'palette' property is not found on the Type 'Theme' within the MUI Property

Having some trouble with MUI and TypeScript. I keep encountering this error message: Property 'palette' does not exist on type 'Theme'.ts(2339) Check out the code snippet below: const StyledTextField = styled(TextField)(({ theme }) = ...