Solucionado (ver solução)
Solucionado
(ver solução)
1
resposta

O console devolve Uncaught SyntaxError: Unexpected token 'if'

Estou tentando inserir um erro quando passarem uma data inválida no console mas ele da erro

DateHelper

class DateHelper {

    constructor() {

        throw new Error('Esta classe não pode se intanciada');
    }

    static dataParaTexto(data) {

        return `${data.getDate()}/${data.getMonth()+1}/${data.getFullYear()}`;

    }

    static textoParaData(texto) 


    if(!/\d{4}-\d{2}-\d{2}/.test(texto)) {
        throw new Error('Deve estar no formato aaaa-mm-dd');
    }

    return new Date(...texto.split('-').map((item, indice) => item - indice % 2));
        }
    }

NegociacaoController

class NegociacaoController  {

    constructor() {    

        let $ = document.querySelector.bind(document);
        this._inputData = $('#data');
        this._inputQuantidade = $('#quantidade');
        this._inputValor = $('#valor');   

    }

    adiciona(event) {

        event.preventDefault();

        let negociacao = new Negociacao(
            DateHelper.textoParaData(this._inputData.value),
                this._inputQuantidade.value,
                this._inputValor.value
            );

        console.log(negociacao);
        console.log(DateHelper.dataParaTexto(negociacao.data));
    }
}
1 resposta
solução!

Cauê,

A sua função textoParaData(texto) falta o colchete de abertura ({).

Tente:

static textoParaData(texto) {
   if(!/\d{4}-\d{2}-\d{2}/.test(texto)) {
      throw new Error('Deve estar no formato aaaa-mm-dd');
   }

   return new Date(...texto.split('-').map((item, indice) => item - indice % 2));
}