I'm working on a browser app and am using the below method to import modules as needed. Unfortunately any modules imported at the 'second level' or deeper treat the asterisk '*' as an unexpected token. It's been a few years since my last JavaScript work and am unsure what I'm doing wrong as much has changed and is new to me.
Below is a minimum example that encounters the issue. The structure of each module is to emulate C# classes with public, private, and static objects and almost entirely remove the need to type 'this.' over and over and over again as is the.js way of doing things.
Content.js
//Directly attached to the page using <script type="module" src="Content.js"></script>
import * as XRVideo from "../Viewer/Scripts/XRVideo.js"; //This works perfectly
var urlA = "Testing/VideoA.mp4";
var urlB = "Testing/VideoB.mp4";
var arrXRVideos = [];
window.addEventListener("load", (e) =>{
arrXRVideos.Push(XRVideo.New(urlA));
arrXRVideos.Push(XRVideo.New(urlB));
});
XRVideo.js
import * as XRScene from "./Core/XRScene.js"; //This throws an Unexpected Token '*' Error
import * as XRSkybox from "./Core/XRSkybox.js";
/* Static */
export const XRStatus = {
Stopped : 0,
};
/* Instanced */
export function New(videoURL){
var _isInitialized = false;
var _url = "";
//#region Pseudo Constructor
{
_url = videoUrl;
_isInitialized = true;
}
//#endregion
/* Getters & Setters */
function GetURL(){
return _url;
}
/* Exposed As Public */
//Properties can't be directly exposed otherwise they become static...
return{
GetURL : GetURL
}
}
It turned out the issue was due to a broken line comment throwing off the system. Always look at the previous line for 'Unexpected' errors...
I didn't notice this due to how VS Code's Default theme, visually styles code comments and hyperlinks the same. Specifically both lines look like the same green text despite one being a comment and the other not.
//This is a comment, VS Code shows it as a dirty green.
//I am a code comment
//This is a URL that accidentally didn't get the '//' to turn it into a comment,
//VS Code shows it as a dirty green making it look like a comment.
https://github.com/blah-blah-blah
import * as Bah from "./Foo.js"; //Unexpected token '*'
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.