1

I have the following code where I am using VAST player to play my ads. I am using a check to see if the user has clicked already to avoid the DOM exception that is present in modern browsers.

(function(VASTPlayer) {
    'use strict';

    var player = new VASTPlayer(document.getElementById(playerID));

    player.once('AdStopped', function() {
        console.log('Ad finished playback! ' + playerID);
        interstitialInstance.close();
    });

    player.load( << Ad Tag >> ).then(function startAd() {
        console.log(player.adDuration + " " + playerID);

        var s = document.getElementById(playerID).childNodes[0];
        if (s) {
            if (!ryads.mouseClick) {
                s.muted = true;
            } else
                s.muted = false;
        } else {
            console.log("Error while fetching video element!!!");
        }

        return player.startAd();
    }).catch(function(reason) {
        console.log('Ad failed to play ' + playerID);
        interstitialInstance.close();
        setTimeout(function() {
            throw reason;
        }, 0);
    });
}(window.VASTPlayer));

I am getting the following error when I run the Compress job in Jenkins.

project.js:891: ERROR - Parse error. missing name after . operator }).catch(function(reason) { ^

project.js:892: ERROR - Parse error. syntax error console.log('Ad failed to play '+playerID); ^

project.js:896: ERROR - Parse error. missing ; before statement }(window.VASTPlayer));

8
  • You are missing a closing parenthesis. Change it to })(window.VASTPlayer)); Commented May 14, 2019 at 6:34
  • @Barmar why did you just fix the code by editing? Commented May 14, 2019 at 6:34
  • @Esko I just fixed the indentation so it was readable. Commented May 14, 2019 at 6:35
  • @Barmar You added the wrapping function? First line. Commented May 14, 2019 at 6:35
  • 1
    Is it all? Looks like some part of the code at the beginning is omitted. Also what is <<Ad Tag>>? It's not a valid JavaScript Commented May 14, 2019 at 6:37

2 Answers 2

3

This is a well known issue since years for yuicompressor. An easy fix for is to extract the resolve and reject functions of the promise like this:

promise.then(successFunction, failureFunction);

function successFunction() {
   console.log('success');
}

function failureFunction(err) {
    console.error(err);
}
Sign up to request clarification or add additional context in comments.

Comments

1

Replace this line

(function(VASTPlayer) {

by

;(function(VASTPlayer) {

Otherwise, when the compression job is trying to concatenate files, your IIFE might be considered an argument to the code that the end of the file contained which was concatenated right before this file.

Can you please elaborate on what

player.load( << Ad Tag >>

is? That is not valid Javascript. Some sort of JSX dialect? Or just a copy/paste error?

7 Comments

I don't think there's a missing ). The second ) in )) matches the ( on the first line.
@Barmar I just saw it was not even your comment, lol. Thanks for pointing out!
player.load actually loads the Ad for playing. The tag is the value provided for the Ad.
@yogeshsriraman Again, that is not valid Javascript. What language is that? JSX? I'm referring to the << Ad Tag >> part.
nodeJS is Javascript, and also there << Ad Tag >> is not valid Javascript.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.