Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bundaling ES class with static field lead to [Error: Line 5: Unexpected token =] #1008

Open
luboid opened this issue May 27, 2021 · 1 comment

Comments

@luboid
Copy link

luboid commented May 27, 2021

Hi,
I'm using
gulp-requirejs:1.4.0
which uses :
requirejs: ^2.3.6
Here is JS code that produces [Error: Line 5: Unexpected token =]
It runs perfectly fine in a browser

define(['$prcbPlugins', 'js/trnsl'], function ($, trnsl) {
	var actionHandlerUrl = '/api/external-notifications';

	class DAL {
		static contentReport = class ContentReport {
			static get(parameters) {
				return $.prcbExecute({
					url: actionHandlerUrl + '/contentreport',
					data: parameters,
					method: 'get'
				}).asPromise();
			}
		};

		static services = class Services {
			static all() {
				return $.prcbExecute({
					url: actionHandlerUrl + '/services',
					method: 'get'
				}).asPromise();
			}
			static get(id) {
				return $.prcbExecute({
					url: actionHandlerUrl + '/services/:id',
					data: { id: id },
					method: 'get'
				}).asPromise();
			}
		};

		static eventTypes = class EventTypes {
			static all() {
				return $.prcbExecute({
					url: actionHandlerUrl + '/eventtypes',
					method: 'get'
				}).asPromise();
			}
			static get(id) {
				return $.prcbExecute({
					url: actionHandlerUrl + '/eventtypes/:id',
					data: { id: id },
					method: 'get'
				}).asPromise();
			}
		};

		static channels = class Channels {
			static all() {
				return new Promise((resolve) => {
					let channels = [
						{ id: 0, title: 'SMS' },
						{ id: 1, title: 'EMail' }
					];
					resolve(channels);
				});
			}

			static providers() {
				return new Promise((resolve) => {
					let channels = [
						{ id: 0, title: 'ProCredit' },
						{ id: 1, title: 'Teracom' },
						{ id: 2, title: 'Mobica' },
					];
					resolve(channels);
				});
			}

			static enum = class Enum {
				static SMS = 0;
				static Email = 1;
			}
		}

		static statuses = class Statuses {
			static all() {
				return new Promise((resolve) => {
					let statuses = [
						{ id: 0, title: trnsl.gettext('за формиране') },
						{ id: 1, title: trnsl.gettext('формиран') },
						{ id: 2, title: trnsl.gettext('завършена комуникация') },
						{ id: 3, title: trnsl.gettext('липсващ или невалиден темплейт') },
						{ id: 4, title: trnsl.gettext('грешка при комуникация') },
						{ id: 5, title: trnsl.gettext('твърде много грешки') },
					];
					resolve(statuses);
				});
			}
		}

		static utils = class Utils {
			static toHash(array, id, descr) {
				if (id === undefined) {
					id = 'id';
				}
				if (descr === undefined) {
					descr = 'title';
				}

				let o = {};
				array.forEach(i => o[i[id]] = i[descr]);

				return o;
            }
        }
	}

	return DAL;
})

Here is config

module.exports = ({
    baseUrl: "../",
    mainConfigFile: 'default.js', //???
    paths: {
        'services': '../../scripts/services',
        'toastr': 'empty:',
        'resources': '../../scripts/jq/requirejs.plugins/resources',
        '$plugins': '../../scripts/jq/plugins',
        'jquery': 'empty:',
        '$prcbPlugins': 'empty:',
        'knockout': 'empty:',
        'knockout.prcb': 'empty:',
        'durandal/activator': 'empty:',
        'durandal/app': 'empty:',
        'durandal/binder': 'empty:',
        'durandal/composition': 'empty:',
        'durandal/events': 'empty:',
        'durandal/history': 'empty:',
        'durandal/http': 'empty:',
        'durandal/observable': 'empty:',
        'durandal/serializer': 'empty:',
        'plugins/widget': 'empty:',
        'durandal/system': 'empty:',
        'durandal/entrance': 'empty:',
        'durandal/viewEngine': 'empty:',
        'durandal/viewLocator': 'empty:',
        'plugins/dialog': 'empty:',
        'plugins/prcb': 'empty:',
        'plugins/prcbroutes': 'empty:',
        'plugins/prcbmessagelistener': 'empty:',
        'plugins/history': 'empty:',
        'plugins/router': 'empty:',
        'globalize': 'empty:',
        'translations': 'empty:',
        'bctx': 'empty:',
        'underscore': 'empty:',
        '$ui': 'empty:'
    },
    optimize: 'none',
    generateSourceMaps: false,
    preserveLicenseComments: true,
    optimizeCss: "none",
    removeCombined: true,
    name: "js/default",
    exclude: [
        // ако при dependency-тата има някой, който не трябва да бъде включен във файла
		'resources'
    ],
    out: 'app.js',
    wrap: true,
    rawText: {
        'translations': 'define(function () { return {}; });',
        'bctx': 'define(function () { return {}; });'
    }
});
@prantlf
Copy link

prantlf commented Apr 23, 2023

The parser bundled to r.js is too old. You'll need to upgrade it. See #998.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants